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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.