O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

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

private static 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required