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

Question 23

Question ID: UKOCP32218


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 is correct and db credentials are: root/password.

SQL query is correct and valid.

The JDBC 4.2 driver jar is configured in the classpath.


What is the result?

  • A John
  • B Sean
  • C Smith
  • D An exception is thrown at runtime
Reveal correct answer

Correct answer: D

Explanation

UKOCP32218:

Variable 'url' infers to String type, variable 'prop' infers to Properties type. Variable 'con' infers to Connection type, variable 'stmt' infers to Statement type and variable 'rs' infers to ResultSet type.


It is assumed that JDBC 4.2 driver is configured in the classpath, hence Class.forName(String) is not required. But no harm in using Class.forName(String).


Class.forName(String) expects fully qualified name of the class but in this case url refers to database url and not fully qualified name of the class, hence ClassNotFoundException is thrown at runtime.

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