JdbcRowSet...

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

Moderator: admin

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

JdbcRowSet...

Post by The_Nick »

So basically, here there is a dilemma:
from this java tutorial: http://docs.oracle.com/javase/tutorial/ ... owset.html
A RowSet object is scrollable and updatable by default, so by populating a RowSet object with the contents of a result set, you can effectively make the result set scrollable and updatable.
and then from this subsequent java tutorial: http://docs.oracle.com/javase/tutorial/ ... owset.html
Passing ResultSet Objects

The simplest way to create a JdbcRowSet object is to produce a ResultSet object and pass it to the JdbcRowSetImpl constructor. Doing this not only creates a JdbcRowSet object but also populates it with the data in the ResultSet object.
Note: The ResultSet object that is passed to the JdbcRowSetImpl constructor must be scrollable.
Why the result set needs to be scrollable if a RowSet object is scrollable by default? Is not that the main advantadge of wrapping a ResultSet in a JdbcRowSet?

Again referring directly to the JdbcRowSet interface:
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.
quoted from the same java tutorial: http://docs.oracle.com/javase/tutorial/ ... owset.html

They in their tutorials quite rim the point that one of the main use of a JdbcRowSet is to add Scrollabilty and Updatability. However by using JdbcRowSetImpl you have to pass a ResultSet which is updatable and scrollable if you want your JdbRowSet object as such.

Now I have posted this question also in stackoverflow and I recieved a confirm that the tutorial contradicts itself. However from this forum I would like to know for the exam questions... what should I reply to a potential question:
What are the main advantages of the JdbcRowSet object in comparison with a ResultSet object?


Thanks in advance. It blowed my mind!
Thanks in advance.

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

Re: JdbcRowSet...

Post by admin »

Benefits are as given here at the top: http://docs.oracle.com/javase/7/docs/ap ... owSet.html

But the most important one which is presented in the exam is:
The RowSet interface supports JavaBeans events, allowing other components in an application to be notified when an event occurs on a rowset, such as a change in its value.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: JdbcRowSet...

Post by The_Nick »

Hi Paul,
I was referring to this contraddiction:

One of the advantages that the oracle java tutorial describes is (besides the rowSetListener thing) that it wraps the underlying ResultSet and even if the database does not support scrollable and updatable ResultSet.TYPE.. the JdbcRowSet or more in general any RowSet as they say will rend that ResultSet updatable and scrollable.

But in the very same tutorial they say the following!:
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 , rs would not be scrollable or updatable, and neither would jdbcRs.
There are 4 ways to instantiate a JdbcRowSet:
1) By passing a ResultSet in the constructor of the implementator es JdbcRowSet jdbcrs = new JdbcRowSetImpl(rs);
2)By passing a Connection Object to the constructor and then setting the properties with the appropriate setters.
3) With a RowSetFactory
4) With the default constructor

So the thing is that with the first method it appears to break the rule of "it add scrollability and updatability" as if the ResultSet passed to the constructor is not declared with Scrollability and Updatability then the wrapping jdbcRs object will be as such (not scrollable and not updatable).

So getting back to the original question:
What should I answer in case of a question like: What are the benefits of a RowSet over a ResultSet?
1) Guarantee updatability and scrollability to the underlying result sets
2) Can make beautiful listener connections with the listener who implement RowSetListener and have themselves added those listeners with jdbcRs.addRowSetListener(listener)
3) It's very useful for callable statement
4) It gives an useful GUI for the underlying JVM.
Choose 2 options;
Of course I would answer the first 2! As the tutorial says! However in the above quoted text (from this oracle [url]tutorial:http://docs.oracle.com/javase/tutorial/ ... owset.html[/url] It states a contraddiction to that benefit.. by using the first way of declaring a JdbcRowSet (by passing to the constructor a ResultSet);

However using other constructors and the RowSetFactory it guarantees those capabilities.

The_Nick

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

Re: JdbcRowSet...

Post by admin »

For the purpose of the exam go with what is given in the API docs not in Tutorial. Since as per API docs, ResultSet and RowSet are both scrollable and updatable, this is not a benefit of RowSet.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 224 guests