[英]Set a default row prefetch in SQL Server using JDBC driver
I have an application where I want to define the default number of rows to prefetch for a connection, using for both Oracle and SQL Server drivers. 我有一个应用程序,我想定义预取连接的默认行数,用于Oracle和SQL Server驱动程序。 The Oracle driver has a the
OracleConnection
interface, which provides the setDefaultRowPrefetch
method to do it, but I didn't find anything equivalent for the SQL Server driver. Oracle驱动程序有一个
OracleConnection
接口,它提供了setDefaultRowPrefetch
方法来执行此操作,但我没有找到与SQL Server驱动程序等效的任何内容。
There is a method to define the default row prefetch for a connection using the SQL Server JDBC driver? 有一种方法可以使用SQL Server JDBC驱动程序为连接定义默认行预取?
The usual ways to set row fetch size are: 设置行提取大小的常用方法是:
java.sql.Connection
vendor implementation class custom method (eg OracleConnection.setDefaultRowPrefetch
) java.sql.Connection
供应商实现类自定义方法 (例如OracleConnection.setDefaultRowPrefetch
) java.sql.Statement.setFetchSize(int)
: gives a hint to the driver as to the row fetch size for all ResultSets
obtained from this Statement
. java.sql.Statement.setFetchSize(int)
:向驱动程序提供有关从此Statement
获取的所有ResultSets
的行提取大小的提示。 This method is inherited by PreparedStatement
and CallableStatement
. PreparedStatement
和CallableStatement
继承。 Most JDBC drivers support it. java.sql.ResultSet.setFetchSize(int)
: gives a hint to the driver as to the row fetch size for all this ResultSet
. java.sql.ResultSet.setFetchSize(int)
:向驱动程序提供有关所有此ResultSet
的行提取大小的提示。 MS SQL Server JDBC driver does not support any of these ways: MS SQL Server JDBC驱动程序不支持以下任何方式:
Statement
. Statement
相同的问题。 By default it retrieves all the rows from database unless you specify cursor type in the JDBC driver. 默认情况下,除非在JDBC驱动程序中指定游标类型,否则它将从数据库中检索所有行。 MSSQL driver can't directly control the fetch size using the usual methods.
MSSQL驱动程序无法使用常用方法直接控制提取大小。
Solutions: 解决方案:
Statement
to SQLServerStatement
and use the method setMaxRows(int)
. Statement
为SQLServerStatement
并使用方法setMaxRows(int)
。 Why they didn't implement this within the standard method Steve Ballmer only knows ;^) Connection
string property selectMethod=cursor
. Connection
字符串属性selectMethod=cursor
。 Alternatively, you can create the Statement
with com.microsoft.sqlserver.jdbc.SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY
scrollability for forward-only, read-only access, and then use the setFetchSize
method to tune performance. com.microsoft.sqlserver.jdbc.SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY
可滚动性创建Statement
,以进行只进,只读访问,然后使用setFetchSize
方法调整性能。 http://technet.microsoft.com/en-us/library/aa342344%28SQL.90%29.aspx SET ROWCOUNT
or SELECT TOP N
SET ROWCOUNT
或SELECT TOP N
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.