It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes why getXXX methods of Resultset require connection open? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "why getXXX methods of Resultset require connection open?" Watch "why getXXX methods of Resultset require connection open?" New topic

why getXXX methods of Resultset require connection open?

Kartik Patel
Ranch Hand

Joined: Sep 12, 2005
Posts: 73
Can Anyone please tell me why getXXX methods of java.sql.resultset requires Connection to be open? Is it going to the datbase each time when there is a getXXX call.

Can anyone give me the official reference link of my understanding?

Please reply with the reliable URL .

Chop your own wood, and it will warm you twice. - Henry Ford
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3640
Yes, if you want to do rs.getXXXX() you need connection to be open. Connection is basically a bridge between your Java Code and Database, and Resultset it just a vehicle running on a bridge. If you want to get any goods (read value) using vehicle (read Resultset) you need a bring (read connection) that connect one end to another end(read Java Code to Database).

Are you clear now?

My blood is tested +ve for Java.
Sunesh Kumar
Ranch Hand

Joined: Oct 17, 2005
Posts: 89
Hi Chetan Bhai,
any mistakes please excuse...

If we use the concept of Cached RowSet we can able to eliminate the concept of going the rs.getXXX every time to the database...


Thanks & Regards<br />Sunesh Kumar Baachu
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The normal result set can be lazy about retrieving rows from the db server. If you do a query that returns a million rows the result set might hold only a 1000 until you do next() to row 1001. This makes things easier on the network between the db and the java container and on Java memory. I suppose it makes more work for the database holding data longer until Java asks for it.

You can break this by going to the last row immediately or by using certain cursors. Somebody more conversant with the details may chime in with more ways.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: why getXXX methods of Resultset require connection open?
It's not a secret anymore!