• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does Result set returns everything or we need hit DB

 
Ambikesh Khiriya
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of my friend asked a simple question around JDBC result set. When you get a result set after executing a query, is every thing returned to you (to java, residing some where Java process memory)? So if you say like resultset.next() you are just accessing a something in the memory itself or you have to make a database call every time. I am assuming its that you get every in one go its just traversal in the memory but will appreciate if I can get some reference about how thing work with result sets internally.

Thanks in advance

Cheers
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDBC has a "fetch size" property that determines how many results are returned for each trip to the database. This means that you get a bunch of records from the database and then go back later for more.

You can read more about it here. I've quoted the beginning of that documentation page.
By default, when Oracle JDBC runs a query, it retrieves a result set of 10 rows at a time from the database cursor. This is the default Oracle row fetch size value. You can change the number of rows retrieved with each trip to the database cursor by changing the row fetch size value.

Standard JDBC also enables you to specify the number of rows fetched with each database round-trip for a query, and this number is referred to as the fetch size. In Oracle JDBC, the row-prefetch value is used as the default fetch size in a statement object. Setting the fetch size overrides the row-prefetch setting and affects subsequent queries run through that statement object.

Fetch size is also used in a result set. When the statement object run a query, the fetch size of the statement object is passed to the result set object produced by the query. However, you can also set the fetch size in the result set object to override the statement fetch size that was passed to it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic