import java.sql.*; public class TestCursor { static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String URL_PROTOCOL = "jdbc:mysql://"; static final String URL_AUTO_RECONNECT = "autoReconnect"; static final String URL_USE_CURSOR_FETCH = "useCursorFetch"; static final String URL_CACHE_PREPARED_STMTS = "cachePrepStmts"; static final String URL_REWRITE_BATCHED_STMTS = "rewriteBatchedStatements"; static final String URL_DEFAULT_FETCH_SIZE = "defaultFetchSize"; static final String USER = "xxxxxx"; // <---------------- Username Here static final String PASS = "xxxxxx"; // <---------------- PW Here public static void main(String[] args) { Connection conn = null; Statement stmt = null; try{ Class.forName("com.mysql.jdbc.Driver"); final StringBuilder builder = new StringBuilder(128); builder.append(URL_PROTOCOL); builder.append("").append(":"); // <---------------- Host Here builder.append("").append("/"); // <---------------- Port Here builder.append("shared"); builder.append("?").append(URL_AUTO_RECONNECT).append("=true"); builder.append("&").append(URL_USE_CURSOR_FETCH).append("=false"); builder.append("&").append(URL_CACHE_PREPARED_STMTS).append("=true"); builder.append("&").append(URL_REWRITE_BATCHED_STMTS).append("=true"); builder.append("&").append(URL_DEFAULT_FETCH_SIZE).append("=").append("10000"); System.out.println("Connecting to database..."); conn = DriverManager.getConnection(builder.toString(),USER,PASS); System.out.println("Creating statement..."); stmt = conn.createStatement( ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); String sql; sql = "SELECT class, inst, data FROM sharedTest"; ResultSet rs = stmt.executeQuery(sql); int pCnt = 0; while( rs.next()) { int pos=0; pCnt++; final long col1 = rs.getLong(++pos); final long col2 = rs.getLong(++pos); final long len = rs.getBlob(++pos).length(); } rs.close(); stmt.close(); conn.close(); }catch(SQLException se){ se.printStackTrace(); }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(stmt!=null) stmt.close(); }catch(SQLException se2){ } try{ if(conn!=null) conn.close(); }catch(SQLException se){ se.printStackTrace(); } } System.out.println("Goodbye!"); } }