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 Statement and it's Fetch Size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Statement and it Watch "Statement and it New topic
Author

Statement and it's Fetch Size

Maneesh Chauahn
Ranch Hand

Joined: Mar 06, 2006
Posts: 48
Hi Everyone,
I have query regarding how jdbc fetches the rows from the database. For exmaple i have a table say item in the database that contains the 1000 records and i want to retrieve these records through JDBC so code is

/*************** Dummy Code *****************************/
Connection conn = DriverManager.getConnection(url,login,pass);
Statement stmt = conn.getStatement();
stmt.setFetchSize(100);
ResultSet rtst = stmt.executeQuery("Select * from item ");
/*********************************************************/

Now the question is that i have 1000 records in the item table and fetch value is 100(which means that 100 rows to be fetched at a time from the datbase ). So how the remaining rows cames in the memory ?

I am unable to understand how JDBC concept works as we have only call executeQuery() in the code

Thanks in advanced for your prompt answer

*** Maneesh Chauhan
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29233
    
138

Maneesh,
When you call rs.next() the driver takes care of this. If there are rows cached in memory, it gives you the next row from there. When it runs out of rows in memory it gets the next X rows, stores them in memory and returns you the first one.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Statement and it's Fetch Size
 
Similar Threads
Problem with Thread..
Help on improving Performance
About ResultSet
Statement.setfetchSize() Doubt
getting top 10 rows