最開始在statement 上面設置fetchsize的緣由是想增長查詢結果返回的速度,由於這樣一會兒就能夠返回更多的數據,可是實際上當咱們加上這個條件的時候,沒有起到效果,反而慢了下來,緣由不知道。對於fetchsize的用法參考官方說明:java
By default, when Oracle JDBC executes a query, it receives the result set 10 rows at a time from the database cursor. This is the default Oracle row-prefetch value. You can change the number of rows retrieved with each trip to the database cursor by changing the row-prefetch value (see "Oracle Row Prefetching" for more information).oracle
JDBC 2.0 also allows 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 executed through that statement object.app
Fetch size is also used in a result set. When the statement object executes 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. (Also note that changes made to a statement object's fetch size after a result set is produced will have no affect on that result set.)ide
The result set fetch size, either set explicitly, or by default equal to the statement fetch size that was passed to it, determines the number of rows that are retrieved in any subsequent trips to the database for that result set. This includes any trips that are still required to complete the original query, as well as any refetching of data into the result set. (Data can be refetched, either explicitly or implicitly, to update a scroll-sensitive or scroll-insensitive/updatable result set. See "Refetching Rows".)fetch
The following methods are available in all Statement
, PreparedStatement
, CallableStatement
, and ResultSet
objects for setting and getting the fetch size:flex
void setFetchSize(int rows) throws SQLException
int getFetchSize() throws SQLException
To set the fetch size for a query, call setFetchSize()
on the statement object prior to executing the query. If you set the fetch size to N, then N rows are fetched with each trip to the database.ui
After you have executed the query, you can call setFetchSize()
on the result set object to override the statement object fetch size that was passed to it. This will affect any subsequent trips to the database to get more rows for the original query, as well as affecting any later refetching of rows. (See "Refetching Rows".)this
Using the JDBC 2.0 fetch size is fundamentally similar to using the Oracle row-prefetch value, except that with the row-prefetch value you do not have the flexibility of distinct values in the statement object and result set object. The row prefetch value would be used everywhere.spa
Furthermore, JDBC 2.0 fetch size usage is portable and can be used with other JDBC drivers. Oracle row-prefetch usage is vendor-specific..net
See "Oracle Row Prefetching" for a general discussion of this Oracle feature.
Note: Do not mix the JDBC 2.0 fetch size API and the Oracle row prefetching API in your application. You can use one or the other, but not both. |
參考博文:https://docs.oracle.com/cd/A87860_01/doc/java.817/a83724/resltse5.htm