About Question enthuware.ocpjp.v7.2.1353 :

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

Moderator: admin

Post Reply
tn1408
Posts: 28
Joined: Wed Dec 04, 2013 7:57 pm
Contact:

About Question enthuware.ocpjp.v7.2.1353 :

Post by tn1408 »

Hello,
#4 is right, it will not compile if Statement is declared outside.
My question is Connection c is created outside. How come that is allowed?

Thanks,

Tony,

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

Re: About Question enthuware.ocpjp.v7.2.1353 :

Post by admin »

Because c is not being managed by try-with-resources.

vcheewei
Posts: 2
Joined: Sun Apr 19, 2015 12:40 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1353 :

Post by vcheewei »

Quick question, do you think rs.getString(0) will execute without exception since column index starts with 1 and not 0?

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

Re: About Question enthuware.ocpjp.v7.2.1353 :

Post by admin »

It should throw an SQLException as per http://docs.oracle.com/javase/7/docs/ap ... tring(int) if the columnIndex is invalid.

You should try it out.

vcheewei
Posts: 2
Joined: Sun Apr 19, 2015 12:40 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1353 :

Post by vcheewei »

Thanks admin, I actually read the documentation beforehand. So would that mean answer 2 is correct as well?

"It will throw an exception every time it is run irrespective of what the query returns."

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

Re: About Question enthuware.ocpjp.v7.2.1353 :

Post by admin »

No, what will happen if the query returns 0 rows?

supafly
Posts: 13
Joined: Mon Apr 18, 2016 2:05 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1353 :

Post by supafly »

The statement at the end "(Assume that items not specified such as import statements and try/catch block are all valid.)" is misleading.

The try with resources statement is part of the try/catch block?

Cheers

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

Re: About Question enthuware.ocpjp.v7.2.1353 :

Post by admin »

Not sure what you find misleading about it. It just means whatever is not specified i.e. whatever is not shown in the given code is valid. For example, the call to DriverManager.getConnection may throw an exception and so this line must either be wrapped in a try/catch block or a throws clause be used for the method in which this code is present.
It has nothing to do with what is shown in the given code.
-Paul.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests