Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zhunina opened this issue Nov 17, 2017 · 2 comments

Comments

@zhunina
Copy link

zhunina commented Nov 17, 2017

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));
	 }
 }
}
@sunsun314
Copy link
Contributor

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
Copy link
Contributor

Known limitations stays open

@sunsun314 sunsun314 reopened this Dec 27, 2017
@yanhuqing666 yanhuqing666 added the limitation Known limitations label Feb 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants