Given this code fragment:
try {
String query = "SELECT * FROM Item";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData rsmd = rs.getMetaData();
int rowCount = rsmd.getRowCount();
System.out.println ("Processing: " + rowCount + " rows.");
while (rs.next()) {
// Process each row
}
} catch (SQLException se) {
System.out.println("Error");
}
Assume that the SQL query returns records. What is the result?
A.
Compilation fails.
B.
The program prints Error
C.
An exception is thrown at runtime
D.
The statement at line 16 execute
Explanation:
There is no GetRowCount method in java.sql.ResultSetMetaData.
The following line will not compile:
int rowCount = rsmd.getRowCount();
Reference: java.sql.ResultSetMetaData