2

There is a database it contains 2 million records approx in a table . and i ran the query from my java code like this " select * from table" . will it fetch the complete data from the database in the result set . or not . If yes then how it will work i want to learn the working on this retrieveal ,

Please let me know , i have learnt somewhere that it will retrieve the complete data from the database and will store in the temporary storage from there it will show in the output .Is it fine . Or is there something related to J2C

Shawn D.
  • 7,895
  • 8
  • 35
  • 47
gaurav
  • 2,886
  • 6
  • 24
  • 26
  • 2
    If you are only using a database to retrieve a large percentage of the table, then perhaps using a database is not the best choice. Databases work best when you only need a small percentage of the data in the database. Otherwise, you are likely to be better off using a file or a simpler persistence store. Getting 2 million entries from a database will take many times longer than from a file. – Peter Lawrey Oct 03 '11 at 06:56

2 Answers2

1

Here's nearly the same question. How to handle huge result sets from database

You ask if it will fetch the complete dataset. it will. therefore, it's advised to not fetch the whole database. Here's something about where it's saved java - mysql - select query outfile - where is file getting saved

Community
  • 1
  • 1
Xavjer
  • 8,838
  • 2
  • 22
  • 42
0

Will it fetch the complete data from the database in the result set

There is no precise answer to it. Its always dependent on the database driver. The result set is an Interface and its implementation is done by a specific database driver. The ResultSet implementation may have its own optimization wherein for smaller set of data, everything is fetched where as for larger datasets, its buffered (or some default paging mechanism). So please refer to the database driver documentation.

There is a standard (at least the javadoc says so) way out to prevent the fetching of large data from database. Set the appropriate fetch size for the JDBC statement as follows java.sql.Statement.setFetchSize().

As the java doc

Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed. The number of rows specified affects only result sets created using this statement. If the value specified is zero, then the hint is ignored. The default value is zero.

Hope this helps.

Santosh
  • 17,667
  • 4
  • 54
  • 79
  • If i won't set the size that how many rows will be retrieved from the database at a time , then will it return 3million records . – gaurav Oct 10 '11 at 06:07
  • It wont. The resultset is in the form of a table which is prepared by the database as a result of query. What you get is the cursor to this table. This is _generally_ the case with most of the database/drivers for the larger dataset. – Santosh Oct 16 '11 at 15:01