About Question enthuware.ocpjp.v7.2.1353 :
Moderator: admin
-
- Posts: 28
- Joined: Wed Dec 04, 2013 7:57 pm
- Contact:
About Question enthuware.ocpjp.v7.2.1353 :
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,
#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,
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1353 :
Because c is not being managed by try-with-resources.
-
- Posts: 2
- Joined: Sun Apr 19, 2015 12:40 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1353 :
Quick question, do you think rs.getString(0) will execute without exception since column index starts with 1 and not 0?
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1353 :
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.
You should try it out.
-
- Posts: 2
- Joined: Sun Apr 19, 2015 12:40 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1353 :
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."
"It will throw an exception every time it is run irrespective of what the query returns."
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1353 :
No, what will happen if the query returns 0 rows?
-
- Posts: 13
- Joined: Mon Apr 18, 2016 2:05 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1353 :
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
The try with resources statement is part of the try/catch block?
Cheers
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1353 :
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.
It has nothing to do with what is shown in the given code.
-Paul.
Who is online
Users browsing this forum: Google [Bot] and 7 guests