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 ResultSet interface - regarding Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "ResultSet interface - regarding " Watch "ResultSet interface - regarding " New topic
Author

ResultSet interface - regarding

Sub swamy
Ranch Hand

Joined: Oct 02, 2002
Posts: 121
When we have a statement such as



Assume a scenario where SQL_QUERY returns 100 rows.

1) Would objects corresponding to these 100 records be created immediately after this statement in the appserver side?

2) Or is it that no objects get created in the app server side until we start accessing the records by saying rs.next() ? In this case, even though the SQL_QUERY could run into a large number of records (a few thousands say), we would create only as many objects corresponding to the number of iteration of while (rs.next())

Would appreciate if someone could throw more light into this.
Rajasekar Elango
Ranch Hand

Joined: Sep 13, 2004
Posts: 105
Hi,

The no of records fetched depends on fetchSize of statement object.
Check out setFetchSize()/getFetchSize() methods of statement.

Basically fetchSize of records will be bufferred and call to rs.next() will reload next fetchSize of records if buffer is exhausted..

You could measure the performance by adjusting fetch size..

Regards,
Raja


SCJP 1.4
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Originally posted by Rajasekar Elango:
Hi,

The no of records fetched depends on fetchSize of statement object.
Check out setFetchSize()/getFetchSize() methods of statement.


I feel this statement needs some correction. The number of records fetched depends on how the driver implements this. setFetchSize allows you to provide "hints" to the driver which may or may not be taken into consideration.
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Originally posted by Subramanian PN:
When we have a statement such as



Assume a scenario where SQL_QUERY returns 100 rows.

1) Would objects corresponding to these 100 records be created immediately after this statement in the appserver side?

2) Or is it that no objects get created in the app server side until we start accessing the records by saying rs.next() ? In this case, even though the SQL_QUERY could run into a large number of records (a few thousands say), we would create only as many objects corresponding to the number of iteration of while (rs.next())

Would appreciate if someone could throw more light into this.


There is no answer to these questions. What will actually happen depends on the type of cursors you use and how your driver and database support those.

The best answer is to use best practices like these

- select as small subsets of data as possible. the database should be doing your record filtering not you
- forward only and read only cursors will cost less than their counterparts. use scrollable and updatable cursors when appropriate but don't abuse them either.
- Always make sure to close all the result sets and statements you open. This will allow the driver and database to release all the resources allocated to your queries, cursors etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet interface - regarding
 
Similar Threads
Implementing scanner into a simple login page
memory leak ??!!
How to retrieve 1 million records in DB2 and write to a file?
HashMap and the While Loop Story
If Statement Problem