aspose file tools*
The moose likes Beginning Java and the fly likes JdbcRowSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JdbcRowSet" Watch "JdbcRowSet" New topic
Author

JdbcRowSet

Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Using JdbcRowSet Objects

A JdbcRowSet object is an enhanced ResultSet object. It maintains a connection to its data source, just as a ResultSet object does. The big difference is that it has a set of properties and a listener notification mechanism that make it a JavaBeans component.

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.


Now
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.

As an example, the following code fragment uses the Connection object con to create a Statement object, stmt, which then executes a query. The query produces the ResultSet object rs, which is passed to the constructor to create a new JdbcRowSet object initialized with the data in rs:

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.


Source:http://docs.oracle.com/javase/tutorial/jdbc/basics/jdbcrowset.html

I don't understand this above contradiction.

In first quote it is written that 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, while in second quote, it is written that ResultSet object must be scrollable to create a JdbcRowSet object.

if my ResulatSet object would have been scrollable capability then why do i think about JdbcRowSet object ?


OCA7
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8403
    
  23

Enkita mody wrote:I don't understand this above contradiction.
In first quote it is written that 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, while in second quote, it is written that ResultSet object must be scrollable to create a JdbcRowSet object.

At first glance it would appear that you're right; however:
(a) You're likely to spend a lot of time being disappointed if you expect documentation to be 100% correct and consistent.
(b) I see nothing in the JdbcRowSet documentation about scrollability. What I DO see, on line 1 is:
"A wrapper around a ResultSet object that makes it possible to use the result set as a JavaBeansTM component."

if my ResultSet object would have been scrollable capability then why do i think about JdbcRowSet object ?

Plenty of reasons:
1. It implements RowSet.
2. It implements Joinable.
3. It appears to encompass not only data, but transaction properties, which is why you can commit() changes.

However, it has to be said that I'm no expert; so I suspect that others will probably be able to offer other reasons as well.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

I had read that JdbcRowSet objects are by default scrollable and updatable, so it is used when a ResultSet object doesn't support these capability.

Suppose i have a ResultSet object but it doesn't support scrollable capability now i think about JdbcRowSet object as it has that capability but it takes a ResultSet object in constructor parameter and this ResultSet object must have scrollable capability ? it looks deadlock.it is impossible.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8403
    
  23

Enkita mody wrote:I had read that JdbcRowSet objects are by default scrollable and updatable, so it is used when a ResultSet object doesn't support these capability.
Suppose i have a ResultSet object but it doesn't support scrollable capability now i think about JdbcRowSet object as it has that capability but it takes a ResultSet object in constructor parameter and this ResultSet object must have scrollable capability?

OK, now I understand your confusion, and I have to admit that I don't know the answer because I've never used the interface.

However, from what I can gather from reading this and this, it would appear that RowSet adds the scrollable and updatable properties to a ResultSet even if the underlying DBMS driver doesn't support it.

Exactly how it does that, or if and when exceptions might be thrown, I don't know; but this document (and particularly point 10.1.4) seems to suggest that, while similar in look and feel, the cursor movement for a RowSet is actually decoupled from its underlying ResultSet.

This thread may also contain some useful information for you.

HIH

Winston
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JdbcRowSet