使用mybatis,javabean中定义了Boolean类型的字段值接收数据库中字段是字符串类型,值是true或false,oracle12的驱动,可以可以正常解析转换,Oracle11的驱动就会报错
Caused by: java.sql.SQLException: 无法转换为内部表示 at oracle.jdbc.driver.CharCommonAccessor.getBoolean(CharCommonAccessor.java:185)
反编译代码Oracle11的驱动,只支持数字转Boolean
boolean getBoolean(int paramInt)
throws SQLException
{
String str = getString(paramInt);
if (str == null) {
return false;
}
str = str.trim();
try
{
BigDecimal localBigDecimal = new BigDecimal(str);
return localBigDecimal.signum() != 0;
}
catch (NumberFormatException localNumberFormatException)
{
SQLException localSQLException = DatabaseError.createSqlException(getConnectionDuringExceptionHandling(), 59);
localSQLException.fillInStackTrace();
throw localSQLException;
}
}
反编译代码Oracle12的驱动,增加了字符串“false”和“true”的支持,还支持“yes”和“no”,以及“t”,“f”,“y”,“n”。
boolean getBoolean(int paramInt)
throws SQLException
{
String str = getString(paramInt);
if ((str == null) || (str.trim().equals("0")) || (str.trim().compareToIgnoreCase("f") == 0) || (str.trim().compareToIgnoreCase("false") == 0) || (str.trim().compareToIgnoreCase("n") == 0) || (str.trim().compareToIgnoreCase("no") == 0)) {
return false;
}
if ((str.trim().equals("1")) || (str.trim().compareToIgnoreCase("t") == 0) || (str.trim().compareToIgnoreCase("true") == 0) || (str.trim().compareToIgnoreCase("y") == 0) || (str.trim().compareToIgnoreCase("yes") == 0)) {
return true;
}
SQLException localSQLException = DatabaseError.createSqlException(getConnectionDuringExceptionHandling(), 59);
localSQLException.fillInStackTrace();
throw localSQLException;
}
对于数据库设计,应该使用NUMBER(1)或CHAr(1)更加合适,并增加默认值。



