Oracle Certified Professional Java Se 8 Programmer · Free Practice Question Hard

Question 2

Given structure of EMPLOYEE table: 

EMPLOYEE (ID integer, FIRSTNAME varchar(100), LASTNAME varchar(100), SALARY real, PRIMARY KEY (ID)) 


EMPLOYEE table contains below records: 


Given code of Test.java file: 


Also assume: 
URL, username and password are correct.
SQL query is correct and valid.
The JDBC 4.2 driver jar is configured in the classpath.


What will be the result of compiling and executing Test class?

  • A

    Program executes successfully and a new record is inserted in the database

  • B

    Program executes successfully but no new record is inserted in the database

  • C

    An exception is thrown at runtime

Reveal correct answer

Correct answer: C

Explanation

By default ResultSet is not updatable. 


'rs.moveToInsertRow();' throws an exception at runtime.


To update the ResultSet in any manner (insert, update or delete), the ResultSet must come from a Statement that was created with a ResultSet type of ResultSet.CONCUR_UPDATABLE.


NOTE: If you want to successfully insert a new record, then replace 'con.createStatement();' with

'con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);'

OR

'con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);'.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need