简体   繁体   English

JDBC ResultSet 与 SQL 服务器

[英]JDBC ResultSet with SQL Server

When query using JDBC createStatement and getting ResultSet of millions of rows (from SQL Server), what SQL queries are really executed, where do the rows are stored and how many rows?当使用 JDBC createStatement 查询并获取数百万行的 ResultSet 时(来自 SQL 服务器),什么 SQL 查询实际存储在哪里? Does it use SQL Server cursor?它是否使用 SQL 服务器 cursor? I know that only a limited number of rows are kept in the client-side memory (where the Java code), so where are the rest of the rows kept, or maybe they are not yet queried from the SQL Server)? I know that only a limited number of rows are kept in the client-side memory (where the Java code), so where are the rest of the rows kept, or maybe they are not yet queried from the SQL Server)? When I looked at SQL Server profiler, it just shows the normal query (it didn't add cursor or TOP X of something else)当我查看 SQL 服务器分析器时,它只显示正常查询(它没有添加 cursor 或其他东西的 TOP X)

Taken from the SQL Server documentation on Adaptive Buffering :取自SQL 服务器文档关于自适应缓冲

Normally, when the Microsoft JDBC Driver for SQL Server executes a query, the driver retrieves all of the results from the server into application memory.通常,当用于 SQL 服务器的 Microsoft JDBC 驱动程序执行查询时,驱动程序会从服务器检索所有结果到应用程序 memory 中。 Although this approach minimizes resource consumption on the SQL Server, it can throw an OutOfMemoryError in the JDBC application for the queries that produce very large results.尽管这种方法可以最大限度地减少 SQL 服务器上的资源消耗,但对于产生非常大结果的查询,它可能会在 JDBC 应用程序中引发 OutOfMemoryError。

There's a way around that, what SQL Server calls Adaptive Buffering and which seems to be enabled by default for JDBC driver version 2+ and you might want to read up on it in the documentation.有一种方法可以解决这个问题,SQL 服务器调用Adaptive Buffering ,它似乎默认为JDBC driver version 2+启用,您可能想在文档中阅读它。 Here's the gist:这是要点:

In order to allow applications to handle very large results, the Microsoft JDBC Driver for SQL Server provides adaptive buffering.为了允许应用程序处理非常大的结果,用于 SQL 服务器的 Microsoft JDBC 驱动程序提供了自适应缓冲。 With adaptive buffering, the driver retrieves statement execution results from the SQL Server as the application needs them, rather than all at once.通过自适应缓冲,驱动程序根据应用程序需要从 SQL 服务器检索语句执行结果,而不是一次全部检索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM