Description:
In my opinion there is a problem with the fetchSize in a ResultSet. The default fetchSize it should be the one set in the Statement (according with the java API doc but the default is 0)
In the code attached there are 3 prints of the getFetchedSize() one from teh statement one from teh ResultSet it should be the same at that is 5 but the output is:
stmt: fetch size: 5
rs: fetch size, should be 5, is: 0
How to repeat:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
public class RS_test {
static Connection conn = null; // database connection object.
static Statement stmt = null; // Statement object.
static ResultSet rs = null; // ResultSet object.
public static void main(String[] arg) {
try {
// Connect to the local database
Class.forName("com.mysql.jdbc.Driver").newInstance();
//just making a connection to a database
conn = DriverManager.getConnection("jdbc:mysql://localhost/tst","root", "");
stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
//seting the FetchSize on 5
stmt.setFetchSize(5);
String sql = "SELECT * FROM test_rs";
System.out.println("stmt: fetch size: " + stmt.getFetchSize());
//creating the result set
rs = (ResultSet)stmt.executeQuery(sql);
System.out.println("rs: fetch size, should be 5, is: " + rs.getFetchSize());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Suggested fix:
After a quick look at the sources (so probably is not the best solution or a solution at all) and starting the investigation from Statement.executeQuery(String sql) method I've concluded the folowing:
In the MysqlIO.buildResultSetWithUpdates(...) method after creating the resultSet that will be returned
ResultSet updateRs = new ResultSet(updateCount, updateID);
you should set the FetchSize with something like this:
updateRs.setFetchSize(stmt.getFetchSize());
where stmt is the initial statement.
Of course after this a testing to see if actualy the fetchSize is working propertly is necesarry.
Best regards,
Daniel Taut
Description: In my opinion there is a problem with the fetchSize in a ResultSet. The default fetchSize it should be the one set in the Statement (according with the java API doc but the default is 0) In the code attached there are 3 prints of the getFetchedSize() one from teh statement one from teh ResultSet it should be the same at that is 5 but the output is: stmt: fetch size: 5 rs: fetch size, should be 5, is: 0 How to repeat: import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import java.sql.ResultSet; public class RS_test { static Connection conn = null; // database connection object. static Statement stmt = null; // Statement object. static ResultSet rs = null; // ResultSet object. public static void main(String[] arg) { try { // Connect to the local database Class.forName("com.mysql.jdbc.Driver").newInstance(); //just making a connection to a database conn = DriverManager.getConnection("jdbc:mysql://localhost/tst","root", ""); stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); //seting the FetchSize on 5 stmt.setFetchSize(5); String sql = "SELECT * FROM test_rs"; System.out.println("stmt: fetch size: " + stmt.getFetchSize()); //creating the result set rs = (ResultSet)stmt.executeQuery(sql); System.out.println("rs: fetch size, should be 5, is: " + rs.getFetchSize()); } catch (Exception e) { e.printStackTrace(); } } } Suggested fix: After a quick look at the sources (so probably is not the best solution or a solution at all) and starting the investigation from Statement.executeQuery(String sql) method I've concluded the folowing: In the MysqlIO.buildResultSetWithUpdates(...) method after creating the resultSet that will be returned ResultSet updateRs = new ResultSet(updateCount, updateID); you should set the FetchSize with something like this: updateRs.setFetchSize(stmt.getFetchSize()); where stmt is the initial statement. Of course after this a testing to see if actualy the fetchSize is working propertly is necesarry. Best regards, Daniel Taut