Assuming the myTable
database exists and contains one empty table named myTable
, what is the output of the following when run using a JDBC 4.0 driver?.
import java.sql.*; public class Main { public static void main (String[] args) throws SQLException { // s1 String url = "jdbc:derby:myTable"; try (Connection conn = DriverManager.getConnection(url); // s2 Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from myTable")) { if (rs.next()) System.out.println(rs.getString(1)); } //from w w w . j ava 2 s . c o m } }
A.
This code correctly obtains a Connection and Statement.
It then runs a query, getting back a ResultSet without any rows.
The rs.next()
call returns false, so nothing is printed, making Option A correct.