Description:
Precondition:
0. Connector/J - 5.1.29, MySQL Community Server - 5.6.15-log, WIN64(x86_64)
1. Stored procedure with out parameter(INTEGER type).
2. properties.put("useUnicode", "true");
properties.put("characterEncoding", "UTF-8");
properties.put("characterSetResults", "UTF-8");
properties.put("useCursorFetch", "true"); // 1
properties.put("defaultFetchSize", "100"); // 2
properties.put("useServerPrepStmts", "true");
3. If (1) and (2) are omitted then it works as expected, in they present exception will be thrown.
4. Code to execute stored procedure:
CallableStatement cstmt = own.prepareCall("{call numberOfUsers(?)}");
cstmt.registerOutParameter(1, Types.INTEGER);
cstmt.execute();
int result = cstmt.getInt(1);
How to repeat:
1. Create stored procedure with integer out parameter (no other parameters are required);
1. Create connection to DB with useCursorFetch=true&defaultFetchSize=100
3. Create java.sql.CallableStatement for this stored procedure (see description).
4. Register type of out parameter (see description).
5. Execute it.
6. Exception will be thrown.
Suggested fix:
I tried to get bytes instead of integer (when (1), (2) are presented)and realized that these bytes represent long value:
byte[] bytes = cstmt.getBytes(1);
byte[] reversed = new byte[bytes.length];
for (int i = 0; i < bytes.length; i++) {
reversed[i] = bytes[bytes.length - 1 - i];
}
long numberOfUsers = ByteBuffer.wrap(reversed).getLong();
Description: Precondition: 0. Connector/J - 5.1.29, MySQL Community Server - 5.6.15-log, WIN64(x86_64) 1. Stored procedure with out parameter(INTEGER type). 2. properties.put("useUnicode", "true"); properties.put("characterEncoding", "UTF-8"); properties.put("characterSetResults", "UTF-8"); properties.put("useCursorFetch", "true"); // 1 properties.put("defaultFetchSize", "100"); // 2 properties.put("useServerPrepStmts", "true"); 3. If (1) and (2) are omitted then it works as expected, in they present exception will be thrown. 4. Code to execute stored procedure: CallableStatement cstmt = own.prepareCall("{call numberOfUsers(?)}"); cstmt.registerOutParameter(1, Types.INTEGER); cstmt.execute(); int result = cstmt.getInt(1); How to repeat: 1. Create stored procedure with integer out parameter (no other parameters are required); 1. Create connection to DB with useCursorFetch=true&defaultFetchSize=100 3. Create java.sql.CallableStatement for this stored procedure (see description). 4. Register type of out parameter (see description). 5. Execute it. 6. Exception will be thrown. Suggested fix: I tried to get bytes instead of integer (when (1), (2) are presented)and realized that these bytes represent long value: byte[] bytes = cstmt.getBytes(1); byte[] reversed = new byte[bytes.length]; for (int i = 0; i < bytes.length; i++) { reversed[i] = bytes[bytes.length - 1 - i]; } long numberOfUsers = ByteBuffer.wrap(reversed).getLong();