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

Question 47

Given structure of MESSAGES table:

MESSAGES (msg1 varchar(100), msg2 varchar(100)) 


MESSAGES table contains below records: 
'Happy New Year!', 'Happy Holidays!'


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 will be the result of compiling and executing Test class?

  • A An exception is thrown at runtime
  • B Compilation error
  • C 1
  • D 0
Reveal correct answer

Correct answer: A

Explanation

stmt.executeQurey(String) method can accept any String and it returns ResultSet instance, hence no compilation error. 


But stmt.executeQuery(String) method cannot issue INSERT, UPDATE and DELETE statements. Hence, 'stmt.executeQuery(query)' throws SQLException at runtime. 


To issue INSERT, UPDATE or DELETE statements either use stmt.execute(String) method OR stmt.executeUpdate(String) method. 



OR


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