enthuware.ocpjp.v7.2.1351

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
santhoshpr4
Posts: 1
Joined: Sun Dec 22, 2013 12:17 am
Contact:

enthuware.ocpjp.v7.2.1351

Post by santhoshpr4 »

Answer for this should be 'It will not compile'.

Connection c = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");

This line will throw SQL Exception and this not handled in the code, this code is placed before the try catch.

is it correct ?

admin
Site Admin
Posts: 10385
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: enthuware.ocpjp.v7.2.1351

Post by admin »

Since this is a partial code listing, you can assume that the code is placed in a method that has appropriate throws clause. That is why there is a statement in the question:
(Assume that items not specified such as import statements and try/catch block are all valid.)

HTH,
Paul.

insider
Posts: 29
Joined: Wed Apr 17, 2013 9:22 am
Contact:

Re: enthuware.ocpjp.v7.2.1351

Post by insider »

Typo: "It moves the cursur"

horst1a
Posts: 37
Joined: Mon Jun 12, 2017 2:16 am
Contact:

Re: enthuware.ocpjp.v7.2.1351

Post by horst1a »

What if the first column in STUDENT were a double ? Should it not throw an Exception?
Shoud it not better say rs.getObject();
Best regards

admin
Site Admin
Posts: 10385
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: enthuware.ocpjp.v7.2.1351

Post by admin »

No, even for double then it will not throw an exception. But you have a point. As per Appendix B of JDBC specification, getString will work for all data types except CLOB, BLOB, ARRAY, REF, STRUCT, JAVA_OBJECT, ROWID, NCLOB, and SQLXML.

For the purpose of exam, however, you can assume that getString will work for all.

HTH,
Paul.

saurabh.agarwal560
Posts: 11
Joined: Thu May 28, 2020 9:53 am
Contact:

Re: enthuware.ocpjp.v7.2.1351

Post by saurabh.agarwal560 »

It will not compile because of try with resource block is not defined properly. There should be no semicolon. Please clarify.

admin
Site Admin
Posts: 10385
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: enthuware.ocpjp.v7.2.1351

Post by admin »

Did you try compiling it?

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests