Connecting to a database
So far, we have used a console to execute SQL statements. The same statements can be executed from Java code using the JDBC API too. But, tables are created only once, so there is not much sense in writing a program for a one-time execution.
Data management, however, is another matter. So, from now on, we will use Java code to manipulate data in a database. In order to do this, we first need to add the following dependency to the pom.xml
file in the database
project:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.2</version>
</dependency>
The example
project also gets access to this dependency because, in the pom.xml
file of the example
project, we have the following dependency on the database .jar
file:
<dependency>
<groupId...