Create, read, update, and delete (CRUD) data
So far, we have used a console to send SQL statements to the database. The same statements could be executed from Java code using the JDBC API, but tables are created only once, so there is not much sense in writing a program for a one-time execution.
But managing data is another matter. That is the primary purpose of a program we are going to write now. In order to do that, first, we add the following dependency to the pom.xml
file because we have installed PostgreSQL 9.6:
<dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.2.2</version> </dependency>
INSERT statement
The SQL statement that creates (populates) data in the database has the following format:
INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);
When several tables records have to be added, it looks like this:
INSERT INTO table_name (column1,column2,column3...