Bug #19568 ResultSet.getInt() does not function correctly on a BIT datatype column
Submitted: 5 May 2006 19:54 Modified: 30 May 2006 21:08
Reporter: Sarit Sotangkur
Status: Closed
Category:Connector/J Severity:S3 (Non-critical)
Version:3.1.10 OS:Microsoft Windows (WinXP)
Assigned to: Target Version:

[5 May 2006 19:54] Sarit Sotangkur
Description:
When calling ResultSet.getInt(<column index>) on a column with datatype
java.sql.Types.BIT results in an error. This is because underlying method
getNativeInt(int) call does not handle BIT and BOOLEAN types and instead relies on the
default call to getNativeString(int) which provides a string that cannot be parsed to an
integer (thus throwing the exception). Example stacktrace shown below:

Caused by: java.sql.SQLException: Invalid value for getInt() - ' ' in column 21
        at com.mysql.jdbc.ResultSet.getIntFromString(ResultSet.java:2419)
        at com.mysql.jdbc.ResultSet.getNativeInt(ResultSet.java:3727)
        at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2338)
        at
org.jboss.resource.adapter.jdbc.WrappedResultSet.getInt(WrappedResultSet.java:323)

How to repeat:
Create a table with a bit datatype column. Insert a row and set the value of the bit
column to 0.

Using the ConnectorJ JDBC driver, run a select statement and try retrieving that column
using ResultSet.getInt(int). You will see the error at that time.

Suggested fix:
In ResultSet.java modify the getNativeInt(int) method and inside the large switch()
statement include a case for MysqlDefs.FIELD_TYPE_BIT and have it call
getNativeBoolean(int) and depending on that returned value, return 1 if true or 0 if
false.

Example code:

case MysqlDefs.FIELD_TYPE_BIT:
    if(getNativeBoolean(columnIndex)) { return 1;} else { return 0;}
[30 May 2006 21:08] Mark Matthews
Fixed for 3.1.13.