JDBC原生实现
注意MySql中
conn.prepareStatement("select * from table",
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
// 这里因为MySQL驱动实现使用Integer.MIN_VALUE来判断是否使用流的方式
preparedStatement.setFetchSize(Integer.MIN_VALUE);
@Test
public void testCursor() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection = DriverManager
.getConnection("jdbc:mysql://127.0.0.1:3306/db?useUnicode=true&characterEncoding=utf8&useSSL=false",
"root", "root");
PreparedStatement preparedStatement =
connection.prepareStatement("select * from table",
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
preparedStatement.setFetchSize(Integer.MIN_VALUE);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
System.err.println(resultSet.getString("