What is the result?

Given the structure of the STUDENT table:
Student (id INTEGER, name VARCHAR)
Given:
public class Test {
static Connection newConnection =null;
public static Connection get DBConnection () throws SQLException {
try (Connection con = DriveManager.getConnection(URL, username,
password)) {
newConnection = con;
}
return newConnection;
}
public static void main (String [] args) throws SQLException {
get DBConnection ();
Statement st = newConnection.createStatement();
st.executeUpdate(“INSERT INTO student VALUES (102, ‘Kelvin’)”);
}
}
Assume that:The required database driver is configured in the classpath.
The appropriate database is accessible with the URL, userName, and passWord exists.
The SQL query is valid.
What is the result?

Given the structure of the STUDENT table:
Student (id INTEGER, name VARCHAR)
Given:
public class Test {
static Connection newConnection =null;
public static Connection get DBConnection () throws SQLException {
try (Connection con = DriveManager.getConnection(URL, username,
password)) {
newConnection = con;
}
return newConnection;
}
public static void main (String [] args) throws SQLException {
get DBConnection ();
Statement st = newConnection.createStatement();
st.executeUpdate(“INSERT INTO student VALUES (102, ‘Kelvin’)”);
}
}
Assume that:The required database driver is configured in the classpath.
The appropriate database is accessible with the URL, userName, and passWord exists.
The SQL query is valid.
What is the result?

A.
The program executes successfully and the STUDENT table is updated with one record.

B.
The program executes successfully and the STUDENT table is NOT updated with any record.

C.
A SQLException is thrown as runtime.

D.
A NullPointerException is thrown as runtime.



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Piotr Droś

Piotr Droś

C: A SQLException is thrown as runtime.
The connection is created in try with resources. So is closed when try clause finishes. Creating statement upon closed connection produces SQLException.

smh

smh

I could not prove this answer in NetBeans. Can you please send me your complete code soI can try in NetBeans. Thanks for your help. you may paste it here in reply. thank you again.

smh

smh

i got it. thank you.

smh

smh

C: A SQLException is thrown as runtime.

Berti John

Berti John

C. is correct