Oracle Certified Professional Java Se 11 Developer · Free Practice Question Medium

Question 96

Question ID: UKOCP56671


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 is the result?

  • A ERROR is printed on to the console
  • B Program executes successfully but no record is updated in the database
  • C Program executes successfully and salary of Sean Smith is updated to 20000
  • D Program executes successfully and salary of Regina Williams is updated to 20000
Reveal correct answer

Correct answer: B

Explanation

UKOCP56671:

Variables 'url', 'user', 'password' and 'query' infer to String type. Variable 'con' infers to Connection type, variable 'stmt' infers to Statement type and variable 'rs' infers to ResultSet type.


Given sql statement returns below records:


rs.absolute(2); moves the cursor pointer to 2nd record.


rs.updateDouble("SALARY", 20000); updates the salary of 2nd record to 20000 but to update the records in the database, rs.updateRow(); statement must be invoked.


As rs.updateRow(); statement is missing hence no record is updated in the database.


Please note: there is no need to invoke con.commit(); method as by default Connection object is in auto-commit mode.

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