So far, we have used a console to execute SQL statements. The same statements can be executed from the 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 the data in a database. In order to do this, we first need to add the following dependency to the pom.xml file:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.2</version>
</dependency>
This matches the PostgreSQL version 9.6 that we have installed. Now we can create a database connection from the Java code, as follows:
String URL = "jdbc:postgresql://localhost/learnjava";
Properties prop = new Properties...