天天看點

MySQL JDBC FetchSize解析

首先是看Java JDBC的API檢視setFetchSize:

Givesthe JDBC driver a hint as to the number of rows that should be fetched from thedatabase when more rows are needed for this ResultSetobject.

檢視的結果給出這裡的rows隻是一個hint,那麼對于MySQL JDBC來說是如何實作的呢?

useCursorFetch

If connected to MySQL > 5.0.2, and setFetchSize() > 0 on a statement, should that statement use cursor-based fetching to retrieve rows?

false

又說是experiment,又說是hint可能被ignore,到底支援還不不支援呢?并且官方文檔給出的這個參數沒說到底是不是會忽略掉fetchSize.按照故事的尿性來說我該看MySQL JDBC的源碼了:

1.首先判斷是否可以進行cursor read

2.如果不滿足,則判斷是否可以進行Streaming Read:

分析到這裡基本上可以确定MySQL也是支援batch fetch的.

本文轉自MIKE老畢 51CTO部落格,原文連結:http://blog.51cto.com/boylook/1308511,如需轉載請自行聯系原作者