是否可以使用 rs.getboolean 方法从 SQL 中获取 tinyint(0/1) 的值? 像这样:
while (rs.next()) {
boolean noUse= rs.getBoolean(1);
}
如果这不起作用,我想你必须这样做:
while (rs.next()) {
boolean noUse= rs.getByte(1)==1;
}
谢谢你帮助我。
最佳答案
选项 1 应该可以正常工作,我也使用过。
while (rs.next()) {
boolean noUse= rs.getBoolean(1);
}
在mysql中,tinyint充当 boolean 值(但物理值保存为0/1) 当你执行上面的代码时,
如果字段值 = 0 那么 ;不使用=假 else 如果字段值= 1 then ;不使用=真
关于java - 我可以在 Java 中使用 resultset.getBoolean 在 SQL 中获取 Tinyint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29131072/