use of cn.hutool.db.handler.NumberHandler in project hutool by looly.
the class SqlConnRunner method count.
/**
* 结果的条目数
* @param conn 数据库连接对象
* @param where 查询条件
* @return 复合条件的结果数
* @throws SQLException SQL执行异常
*/
public int count(Connection conn, Entity where) throws SQLException {
checkConn(conn);
final Query query = new Query(DbUtil.buildConditions(where), where.getTableName());
PreparedStatement ps = null;
try {
ps = dialect.psForCount(conn, query);
return SqlExecutor.query(ps, new NumberHandler()).intValue();
} catch (SQLException e) {
throw e;
} finally {
DbUtil.close(ps);
}
}
Aggregations