How to do it...

First, let's add an output to the traverseRS() method: 

void traverseRS(String sql){  System.out.println("traverseRS(" + sql + "):");  try (Connection conn = getDbConnection()) {    ...  }}

This will help you analyze the output when many different SQL statements are executed in the same demo example. 

Now, let's run the following code that reads data from the enums table, then inserts a row, and then reads all the data from the table again:

traverseRS("select * from enums");System.out.println();try (Connection conn = getDbConnection()) {  conn.setAutoCommit(false);  String sql = "insert into enums (id, type, value) "                       + " values(1,'vehicle','car')";  try (PreparedStatement st = conn.prepareStatement(sql)) {    System.out.println(sql)

Get Java 11 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.