我需要使用 DBUtils 获得标量值,有人知道如何获得它吗?目前我做:
String sql = "SELECT count(*) FROM t1 WHERE cod = ?";
final QueryRunner run = new QueryRunner(new AppDataSource());
ScalarHandler scalar = new ScalarHandler();
long count = -1l;
try{
Object[] params =
{
code
};
count = ((Long) run.query(sql, scalar, params)).longValue();
}
catch(SQLException e){
e.printStackTrace();
}
System.out.println(count);
但结果仍然是-1。当我用 db util 测试它时,我得到了正确的数字。