File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Behaviour of ResultSet 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 » Databases » JDBC
Bookmark "Behaviour of ResultSet" Watch "Behaviour of ResultSet" New topic
Author

Behaviour of ResultSet

Abhishk Singh
Ranch Hand

Joined: Aug 19, 2010
Posts: 45
On reaching statement 2 in:
Statement 1;
resultset = prepstmt.executeQuery();
Statement 2;
,can we assume that all the required data has been fetched ?
I mean to ask that when we reach the statement: while(resultset.next()) ,is it the case that all the data has been fetched and filled in the resultset or the resultset keeps on getting updated when the while loop is running ?
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

Hi Abhishek , Welcome to JavaRanch.

No you can't assume that all the required data has been fetched . You can't think of a ResultSet as a container that holds your data.
After you execute your query, the ResultSet serves as a gateway to retrieve that resultsfrom the database.
That is what you do with while (ResultSet.next()):
You loop over the rows returned by the SQL statement, and the ResultSet serves these rows one by one.

The resultset is not updated during the while (next()) loop, but the record pointer is moved to the next row.

(note and disclaimer: simplified explanation. We don't know how a JDBC driver actualy fulfills this functionality)


OCUP UML fundamental and ITIL foundation
youtube channel
Avishkar Nikale
Ranch Hand

Joined: Aug 06, 2010
Posts: 173
Jan Cumps wrote:Hi Abhishek , Welcome to JavaRanch.

No you can't assume that all the required data has been fetched . You can't think of a ResultSet as a container that holds your data.
After you execute your query, the ResultSet serves as a gateway to retrieve that resultsfrom the database.


Nice explanation Jan.


Regards,
Avishkar Nikale
Ravi Shankar Kumar
Ranch Hand

Joined: Aug 08, 2008
Posts: 30
    
    1

yes jan is 100% right resultset is like a pointer


Ravi Shankar Kumar
SCJP 1.5, (Following-OCWCD)
Abhishk Singh
Ranch Hand

Joined: Aug 19, 2010
Posts: 45
hi everyone,thanks for the info.
one more querstion: could you tell something about usage and effects of resultset.setFetchSize(); ?
what is referred to by FetchSize?
Avishkar Nikale
Ranch Hand

Joined: Aug 06, 2010
Posts: 173
abhishek singhania wrote:
could you tell something about usage and effects of resultset.setFetchSize(); ?
what is referred to by FetchSize?


Hi Abhishek,

Refer to the JDBC API for more details about what the spec demands/assures.

http://download.oracle.com/javase/6/docs/api/java/sql/ResultSet.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Behaviour of ResultSet