简体   繁体   中英

Java 1.7 CachedRowSet.populate() turns MySQL TINYINT(1) into Boolean. Can this be disabled?

As the title states, feeding a ResultSet that contains a TINYINT(1) column to a CachedRowSet throught its populate() method will convert the values in that column to booleans with values false for 0 and true for anything above. This loses the original value and makes a getInt() call for that column throw an exception.

Can this behaviour be disabled? TINYINT(1) is also very useful for hardcoded types and statuses. It's a number with 1 digit, not a number where 1 is max value. No reason to treat it as boolean, really.

Anything I can do to disable this when instantiating CachedRowSetImpl?

在SQL中使用强制转换 ,这样您就可以返回普通的int了:

select cast(tinyIntColumn as int) from someTable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM