天天看点

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,如需转载请自行联系原作者