java 从数据库中检索一百万条记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7631654/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Retrieving a million records from a database
提问by gaurav
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 ,
有一个数据库,它在一个表中包含大约 200 万条记录。我从我的 Java 代码中运行查询,就像这样“从表中选择 *”。它将从结果集中的数据库中获取完整的数据。或不 。如果是,那么它将如何工作,我想学习这个检索的工作,
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
请让我知道,我在某处了解到它将从数据库中检索完整的数据,并将从那里存储在临时存储中,它将显示在输出中。是否可以。或者有没有与J2C相关的东西
采纳答案by Santosh
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 mayhave 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.
对此没有准确的答案。它始终依赖于数据库驱动程序。结果集是一个接口,它的实现由特定的数据库驱动程序完成。ResultSet 实现可能有自己的优化,其中对于较小的数据集,所有内容都被提取,而对于较大的数据集,它是缓冲的(或一些默认的分页机制)。所以请参考数据库驱动文档。
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()
.
有一种标准(至少 javadoc 是这样说的)方法可以防止从数据库中获取大数据。为 JDBC 语句设置适当的提取大小,如下所示java.sql.Statement.setFetchSize()
。
As the java doc
作为 java 文档
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.
向 JDBC 驱动程序提供有关在需要更多行时应从数据库中提取的行数的提示。指定的行数仅影响使用此语句创建的结果集。如果指定的值为零,则忽略提示。默认值为零。
Hope this helps.
希望这可以帮助。
回答by Xavjer
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
你问它是否会获取完整的数据集。它会。因此,建议不要获取整个数据库。这里有一些关于它的保存位置java - mysql - 选择查询输出文件 - 文件在哪里保存