useCursorFetch

2023-07-26 09:37:05  Updated

A cursor is a data processing method that allows you to browse one or more rows forward or backward in a result set at a time, for you to view or process data in the result set.

The following example shows how to use useCursorFetch to return a cursor result set:

  1. Establish a link and set parameters useCursorFetch and useServerPrepStmts.

    String url = "jdbc:mysql://host:port/test?useServerPrepStmts=false&useCursorFetch=true"conn = DriverManager.getConnection(url,"admin@mysql", "admin");
    

Note

If useServerPrepStmts=false, when useCursorFetch is set to true, useServerPrepStmts is forcibly changed to true.

  1. Generate a prepared statement.

    PreparedStatement pstmt = conn.prepareStatement("select * from tab",ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    
  2. Set FetchSize.

    pstmt.setFetchSize(3);
    
  3. Execute the statement.

    ResultSet rs = pstmt.executeQuery();
    
  4. Cyclically obtain the next row of data.

    while (rs.next()) {}
    

Contact Us