import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.CallableStatement; public class testCase42456 { static Connection conn = null; static int rows = 10000; /** * @param args */ public static void main(String[] args) { createConnection(); setupTest(); runTest(); cleanupTest(); } public static void createConnection() { try { conn = DriverManager.getConnection("jdbc:mysql://localhost/test?" + "characterEncoding=utf8&" + "user=root"); } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } } public static void setupTest() { Statement stmt = null; // create the table String createQuery = "CREATE TABLE `t1` (" + "`c1` longblob," + "`id` int(11) NOT NULL auto_increment," + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB AUTO_INCREMENT=30000000 DEFAULT CHARSET=utf8"; String insertQuery = "INSERT INTO t1 (c1) VALUES (?)"; try { stmt = conn.createStatement(); CallableStatement cStmt = conn.prepareCall(insertQuery); stmt.execute(createQuery); conn.setAutoCommit(false); for (int i = 0;i< rows;i++) { byte[] b = new byte[10]; b[0] = (byte)0xAA; cStmt.setBytes(1, b); cStmt.execute(); } conn.commit(); conn.setAutoCommit(true); } catch (SQLException ex){ // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException sqlEx) { } // ignore stmt = null; } } } public static void runTest() { Statement stmt = null; Statement status_stmt = null; ResultSet rs = null; ResultSet rs_status = null; try { status_stmt = conn.createStatement(); stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_UPDATABLE); stmt.setFetchSize(Integer.MIN_VALUE); rs = stmt.executeQuery("SELECT * FROM t1"); rs_status = status_stmt.executeQuery("SHOW SESSION STATUS LIKE 'Handler%';"); System.out.print("Before:\n\n"); while (rs_status.next()){ System.out.printf("%s: %s\n", rs_status.getString(1), rs_status.getString(2)); } for (int i = 0; i < rows /2;i++) rs.next(); rs.deleteRow(); System.out.print("\n\n\nAfter:\n\n"); rs_status = status_stmt.executeQuery("SHOW SESSION STATUS LIKE 'Handler%';"); while (rs_status.next()){ System.out.printf("%s: %s\n", rs_status.getString(1), rs_status.getString(2)); } } catch (SQLException ex){ // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } finally { if (rs != null) { try { rs.close(); } catch (SQLException sqlEx) { } rs = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException sqlEx) { } // ignore stmt = null; } } } public static void cleanupTest() { Statement stmt = null; String dropQuery = "drop table t1"; try { stmt = conn.createStatement(); stmt.execute(dropQuery); } catch (SQLException ex){ // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException sqlEx) { } // ignore stmt = null; } } } }