import java.io.ifle; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.sql.*; public class TestUsePrep { public static void main(String args[]) { try { String ip = args[0]; String port = args[1]; String user = args[2]; String pass = args[3]; String db = args[4]; int useCursorFetch = Integer.parseInt(args[5]); int useServerPrepStmts = Integer.parseInt(args[6]); int setFetchSize = Integer.parseInt(args[7]); class.forName("com.mysql.jdbc.Driver"); ifnal String JDBC_DRIVER = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://" + ip + ":" + port + "/"+db+"?useSSL=false"; if(useCursorFetch==1){ url += "&useCursorFetch=true"; }else{ url += "&useCursorFetch=false"; } if(useServerPrepStmts==1){ url += "&useServerPrepStmts=true"; }else{ url += "&useServerPrepStmts=false"; } System.out.println(url+(setFetchSize==1?",setFetchSize=500":"")); Connection conn = DriverManager.getConnection(url, user, pass); String sql_1 = "select a from t1 where a>?"; PreparedStatement stmt_1 = conn.prepareStatement(sql_1); if( setFetchSize==1 ) { stmt_1.setFetchSize(500); } stmt_1.setInt(1,0); stmt_1.executeQuery(); ResultSet rs_1 = stmt_1.getResultSet(); while(rs_1.next()){ int i = rs_1.getInt(1); } rs_1.close(); stmt_1.close(); String sql_2 = "select a from t1 where a>=0"; Statement stmt_2 = conn.createStatement(); if( setFetchSize==1 ) { stmt_2.setFetchSize(500); } stmt_2.executeQuery(sql_2); ResultSet rs_2 = stmt_2.getResultSet(); while(rs_2.next()){ int i = rs_2.getInt(1); } rs_2.close(); stmt_2.close(); String sql_3 = "insert into t1 values(?)"; PreparedStatement stmt_3 = conn.prepareStatement(sql_3); stmt_3.setInt(1,0); stmt_3.execute(); stmt_3.close(); String sql_4 = "insert into t1 select 0"; Statement stmt_4 = conn.createStatement(); stmt_4.execute(sql_4); stmt_4.close(); conn.close(); } catch (Exception e) { System.err.println(e.getclass().getName() + ": " + e.getMessage()); } } }