dble icon indicating copy to clipboard operation
dble copied to clipboard

'stm=conn.createStatement()+stm.setFetchSize(Integer.MIN_VALUE) 'makes 'stm.setMaxRows(1)' lost efficacy

Open zhunina opened this issue 7 years ago • 2 comments

public class TestStatement {
	 Connection conn=null;
         Statement stm=null;
         String sql_simple_sql="select * from t3";
	 String[] sql_muti_sql=new String[2];
	 String create_sql="create table t3(id int primary key,name varchar(8))";
	 String drop_sql="DROP TABLE IF EXISTS  t3";
	 String delete_sql="delete from t3 where id=1";
	 String update_sql="update t3 set name='bb' where id=3";
	 static String[] insert_sql=new String[9];	 
	 static {
		 insert_sql[0]="insert into t3 values(1,'aa')";
		 insert_sql[1]="insert into t3 values(2,'aa')";
		 insert_sql[2]="insert into t3 values(3,'aa')";
		 insert_sql[3]="insert into t3 values(4,'aa')";
		 insert_sql[4]="insert into t3 values(5,'aa')";
		 insert_sql[5]="insert into t3 values(6,'aa')";
		 insert_sql[6]="insert into t3 values(7,'aa')";
		 insert_sql[7]="insert into t3 values(8,'aa')";
		 insert_sql[8]="insert into t3 values(9,'aa')";
			 };
 public  Connection bulidConnection(String url){
	  	Connection conn=null;
	  	String Url=url;
		String user = "test";
		String password = "test";
		Properties info = new Properties();
		info.setProperty("user", user);
		info.setProperty("password", password);
       try {
           Class.forName("com.mysql.jdbc.Driver").newInstance();
           System.out.println("loadDriver successfully");
       } catch (Exception ex) {
       }
       
       try {
       	conn = DriverManager.getConnection(Url, info);
           System.out.println("create connecton successfully:"+conn);
          
       } catch (SQLException ex) {
           System.out.println("SQLException: " + ex.getMessage());
           System.out.println("SQLState: " + ex.getSQLState());
           System.out.println("VendorError: " + ex.getErrorCode());
   }	
       return conn;
 }
 @BeforeMethod
 public  void initializationBlob() throws SQLException, IOException{
	String urldble="jdbc:mysql://10.186.21.74:8066?defaultFetchSize=2&useCursorFetch=true";
	conn=bulidConnection(urldble);
        conn.setCatalog("testdb");
        stm=conn.createStatement();
        stm.addBatch(drop_sql);
	stm.addBatch(create_sql);
	stm.addBatch(insert_sql[0]);
	stm.addBatch(insert_sql[1]);
	stm.addBatch(insert_sql[2]);
	stm.addBatch(insert_sql[3]);
	stm.addBatch(insert_sql[4]);
	stm.addBatch(insert_sql[5]);
	stm.addBatch(insert_sql[6]);
	stm.addBatch(insert_sql[7]);
 }
 @AfterMethod
 public  void freeResource() throws SQLException{
	stm.close();
	conn.close();
	stm1.close();
	conn1.close();
 }
 @Test
 public void testSetMaxRows() throws SQLException{
         stm.setFetchSize(Integer.MIN_VALUE);
	 stm.setMaxRows(1);
	 ResultSet rs=stm.executeQuery(sql_simple_sql);
         while(rs.next()){
		 System.out.println("id:"+rs.getInt(1));
		 System.out.println("name:"+rs.getString(2));
	 }
 }
}

zhunina avatar Nov 17 '17 03:11 zhunina

It's because of the dble did not support the sql 'set sql_select_limit' very well ,and jdbc will make sure the result set size when only set the MaxRows parameter

sunsun314 avatar Nov 21 '17 09:11 sunsun314

Known limitations stays open

sunsun314 avatar Dec 27 '17 06:12 sunsun314