Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About ResultSet and used memory

 
Andrew Nomos
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

in the JDBC API it is said that a ResultSet is an object that maintains a cursor pointing to its current row of data.
What does that mean in terms of memory?

For example, when I execute a database query that returns 500.000 records, the ResultSet will not acctually keep the 500.000 records, won't it? But what actually gets send to my machine?

Any comments are highly appreciated.

Thanks,
Andrew
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andrew Nomos:
Hello,

in the JDBC API it is said that a ResultSet is an object that maintains a cursor pointing to its current row of data.


Yes this is correct


What does that mean in terms of memory?


It means that there is nothing being hold in your JVM's memory



For example, when I execute a database query that returns 500.000 records, the ResultSet will not acctually keep the 500.000 records, won't it? But what actually gets send to my machine?


Whenever you execute any query, a cursor is maintianed at database and every resultset.next() makes cursor to move at next row.
Hence every rs.next() casues a round trip to database, and current row is sent to your machine.

hope this answers to your question
Shailesh
[ June 30, 2005: Message edited by: Shailesh Chandra ]
 
Alin Sinpalean
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shailesh Chandra:
It means that there is nothing being hold in your JVM's memory


Not necessarily. There are cases (such as when using scrollable result sets with Oracle or when executing simultaneous statements) when the JDBC driver will have no choice but to create a client side cursor, i.e. cache the whole result set to memory and/or disk. Read the documentation of the driver(s) you are using to see when and whether this happens.


Whenever you execute any query, a cursor is maintianed at database and every resultset.next() makes cursor to move at next row.
Hence every rs.next() casues a round trip to database, and current row is sent to your machine.


Again, this is not entirely correct. Except the cases described above, when the whole result set is retrieved and cached by the driver, there's also such a thing as fetch size (see Statement and ResultSet.setFetchSize()). A JDBC driver will typically fetch more than one row at once (e.g. 100 rows) and provide you with rows from that buffer; when you've gotten to the end of that buffer the driver will fetch another set of rows. The number of rows fetched can be controlled via the setFetchSize() methods mentioned above.

Alin,
The jTDS Project.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alin,

that was my level one info to poster, I know the facts told by you..seems its not my day today

thanks for a detailed answer and Welcome to Ranch...

Shailesh
[ June 30, 2005: Message edited by: Shailesh Chandra ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic