3
我需要用DBUtils得到標量值,有人知道如何得到它嗎?目前我做:Apache 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測試它時,我得到了正確的數字。