Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Won't Fix
-
None
-
None
-
None
-
Operating System: All
Platform: All
-
36822
Description
Found that I was repeating the same bit of code over and over again when executing SELECT COUNT(...)
sql queries with QueryRunner, so I thought I might code this up into a set of static methods for possible
inclusion in commons-dbutils.
e.g.
Connection conn;
String sql = "select count from tablename where column0 = ? and column1 = ?";
from:
int count = 0;
Object result = QueryRunner.query(conn, sql, new Object[]
if (result != null) {
count = ((Integer) result).intValue();
}
to:
int count = QueryRunner.count(conn, sql, new Object[] { "foo", "bar" }
);
See attached diff.txt.