About Question enthuware.ocpjp.v7.2.1269 :

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

Moderator: admin

Post Reply
Elmcrest
Posts: 12
Joined: Sat Apr 20, 2013 10:06 am
Contact:

About Question enthuware.ocpjp.v7.2.1269 :

Post by Elmcrest »

Hello!

I'm a bit confused about the following answer:
"A JdbcRowSet object can be used to make a ResultSet object scrollable and updatable."

Based on this statement I would conclude that I have a ResultSet object and that I wrap it into a JdbcRowSet by using the JdbcRowSetImpl(ResultSet) constructor. However you cannot make a ResultSet scrollable or updateable by using this constructor,
see http://docs.oracle.com/javase/tutorial/ ... owset.html
"A JdbcRowSet object created with a ResultSet object serves as a wrapper for the ResultSet object. Because the RowSet object rs is scrollable and updatable, jdbcRs is also scrollable and updatable. If you have run the method createStatement without any arguments, rs would not be scrollable or updatable, and neither would jdbcRs."
I even tried this out, and got an Exception, as expected:

Code: Select all

     [java] java.sql.SQLException: ResultSet is not updatable
     [java] 	at com.sun.rowset.JdbcRowSetImpl.checkTypeConcurrency(JdbcRowSetImpl.java:4155)
     [java] 	at com.sun.rowset.JdbcRowSetImpl.updateFloat(JdbcRowSetImpl.java:2366)
     [java] 	at com.sun.rowset.JdbcRowSetImpl.updateFloat(JdbcRowSetImpl.java:2779)
     [java] 	at com.oracle.tutorial.jdbc.JdbcRowSetSample.testJdbcRowSet(JdbcRowSetSample.java:101)
     [java] 	at com.oracle.tutorial.jdbc.JdbcRowSetSample.main(JdbcRowSetSample.java:179)
Strangely the javadoc of JdbcRowSet is confirming your answer, see http://docs.oracle.com/javase/7/docs/ap ... owSet.html
"Another advantage of a JdbcRowSet object is that it can be used to make a ResultSet object scrollable and updatable. All RowSet objects are by default scrollable and updatable. If the driver and database being used do not support scrolling and/or updating of result sets, an application can populate a JdbcRowSet object with the data of a ResultSet object and then operate on the JdbcRowSet object as if it were the ResultSet object."
Could someone please be so kind to explain to me what I'm missing here?

Best regards

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

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

Post by admin »

Doesn't look you are missing anything. Since the documentation itself is contradictory, I am not sure what can be done here. If you get a question on this aspect, it is anybody's guess what option is considered correct by Oracle.

HTH,
Paul.

codecodecode67
Posts: 14
Joined: Sun Dec 06, 2015 2:15 pm
Contact:

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

Post by codecodecode67 »

https://docs.oracle.com/javase/tutorial ... owset.html

Code: Select all

stmt = con.createStatement(
           ResultSet.TYPE_SCROLL_SENSITIVE,
           ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("select * from COFFEES");
jdbcRs = new JdbcRowSetImpl(rs);
A JdbcRowSet object created with a ResultSet object serves as a wrapper for the ResultSet object. Because the RowSet object rs is scrollable and updatable, jdbcRs is also scrollable and updatable. If you have run the method createStatement without any arguments, rs would not be scrollable or updatable, and neither would jdbcRs.
You CAN make a ResultSet scrollable & updatable by using a JdbcRowSet - to do it, you have to run createStatement() with arguments as in the above example that they have provided. The documentation is confusing :| but not contradicting :) .

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

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

Post by admin »

That makes sense.
Thanks for providing this information.
Paul.

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

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

Post by insider »

Documentation and Oracle tutorial are indeed contradictory.
JdbcRowSet seems to act as a wrapper on ResultSet and it simply delegates the scrolling/updating calls to RS.
If RS was created as scrollable and updatable, we can't say that JdbcRowSet has made it like that since it already was that way.
If RS was created in default mode (not scrollable or updatable), wrapping JdbcRowSet will not make it scrollable or updatable. Such calls would result in exception, as seen in topic-starter's post.

Oracle tutorial contradicts itself:
"One of the main uses of a JdbcRowSet object is to make a ResultSet object scrollable and updatable when it does not otherwise have those capabilities."
"A JdbcRowSet object created with a ResultSet object serves as a wrapper for the ResultSet object. Because the RowSet object rs is scrollable and updatable, jdbcRs is also scrollable and updatable. If you have run the method createStatement without any arguments, rs would not be scrollable or updatable, and neither would jdbcRs."

I'll try to drop them a complaint today.

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests