What is the output when run with a JDBC 4.0 driver if the clowns database exists and contains an empty clowns table?
String url = "jdbc:derby:clowns"; try (Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select count(*) from clowns")) { System.out.println(rs.getInt(1)); }
D.
This code is missing a call to rs.next()
.
As a result, rs.getInt(1) throws a SQLException with the message Invalid cursor state - no current row.
Therefore, Option D is the answer.