另一方面,问题记述问题:使用Java的jdbc读取tinyint(1)类型的数据时,rs.getObject(i ) I的值为Boolean类型的true/false。 数据库中存储了1或0,但为什么用JDBC读取的是true或false呢?
因此,请注意JAVA数据类型和MYSQL数据类型转换是tinyInt类型,内存长度为1。
二.原因分析MYSQL公式的JDBC文档定义转换规则如下:
官方文档地址: https://dev.MySQL.com/doc/connector-j/5.1/en/connector-j-reference-type-conversions.html
mysqltypestojavatypesforresultset.getobject (
ava.lang.booleaniftheconfigurationpropertytinyint1isbitissettotrue (the default ) and the storage size is 1,orJava.lang.lang
翻译:
如果tinyInt1isBit=true (默认值),且tinyInt存储长度为1,则为java.lang.Boolean; 否则,迁移到java.lang.Integer。
注:是ResultSet.getObject ()方法
三、解决方案1,tinyint(1)只用于表示布尔意义的字段,0表示假,1表示真。 如果存储多个数值,则定义为tinyint(n )、N1。 例如tinyint(2)。
2、请注意将 tinyInt1isBit=false参数添加到JDBC的URL中,参数名称区分大小写。 否则,将无法生效
JDBC : MySQL ://localhost :3306/test?tinyInt1isBit=false
相关文章:
3358 www.Sina.com/https://blog.csdn.net/dujianxiong/article/details/60571395
【2】https://blog.csdn.net/cod olio/article/details/6591493