import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; /** * */ /** * Test case for MySQL CursorFetch bug */ public class CursorFetchTest { private static final String DRIVER = "com.mysql.jdbc.Driver"; private static final String CONNECT_URI = "jdbc:mysql://localhost:3306/DB1N1?useCursorFetch=true"; private static final String USER = "user"; private static final String PASSWORD = "password"; public static void main(String[] args) throws Exception { Class.forName(DRIVER); Connection conn = DriverManager.getConnection(args[0], args[1], args[2]); try { // Create test table Statement stmtWrite = conn.createStatement(); stmtWrite.executeUpdate("create table foo (foo_key int)"); try { Statement stmtRead = conn.createStatement(); stmtRead.setFetchSize(1000); // Insert test data stmtWrite.executeUpdate("insert into foo values (1)"); stmtWrite.executeUpdate("insert into foo values (2)"); stmtWrite.executeUpdate("insert into foo values (3)"); stmtWrite.executeUpdate("insert into foo values (4)"); // Execute test query ResultSet rs = stmtRead.executeQuery("select 5 as expression1, foo.foo_key from foo where (foo.foo_key = 3)"); try { // Dump results while (rs.next()) { System.out.printf("%d\t%d\n", new Object[] {rs.getInt(1), rs.getInt(2)}); } } finally { rs.close(); } } finally { // Clean up stmtWrite.executeUpdate("drop table foo"); } } finally { conn.close(); } } }