ScalarHandler对象获取 数据库中的数据是注意转换

时间:2017-10-22 18:18:25   收藏:0   阅读:1644

/**
* 获取数据库总数据条数
* @return
* @throws SQLException
*/
public int FindTotalCount() throws SQLException {
// TODO Auto-generated method stub
QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
String sql="select count(*) from product ";
//((Long) qr.query(sql, new ScalarHandler())).intValue() ;

/qr.query()返回object类型 ,先转成 ScalarHandler的Long类型 然后 在转为 int类型
return ((Long) qr.query(sql, new ScalarHandler())).intValue();
}

原文:http://www.cnblogs.com/nextgg/p/7710091.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!