Return to site

JAVA PREPARED STATEMENT QUIZ

· java

Input

Assume there is an empty APP.BOOK table with the following definition:
ID: INTEGER
TITLE: VARCHAR(40)
EDITION: INTEGER

Snippet

//Here is code that uses this table:
PreparedStatement psInsert = conn.prepareStatement("INSERT INTO APP.BOOK (ID, TITLE, EDITION) VALUES (?, ?, ?)");
psInsert.setInt(1, 1);
psInsert.setString(2, "Java for Beginners");
psInsert.setInt(3, 1);
psInsert.executeUpdate();

psInsert.setInt(1, 2);
psInsert.setInt(3, 2);
psInsert.executeUpdate();//line n1

PreparedStatement psUpdate = conn.prepareStatement("UPDATE APP.BOOK SET TITLE = ? WHERE ID = ?");
psUpdate.setString(1, "JDBC for Beginners");
psUpdate.setInt(2, 1);
psUpdate.executeUpdate();

psUpdate.setInt(2, 2);
psUpdate.executeUpdate();//line n2

Question

What will be the table state after the code runs?

 

 

 

 

 

 

 

 

 

 

 

Answer

1 JDBC for Beginners 1
2 JDBC for Beginners 2