Uploaded image for project: 'Commons DbUtils'
  1. Commons DbUtils
  2. DBUTILS-27

[dbutils] QueryRunner.count(String, ...) methods for SELECT COUNT(...) sql

    XMLWordPrintableJSON

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[]

      { "foo", "bar" }, new ScalarHandler());
      if (result != null) {
      count = ((Integer) result).intValue();
      }

      to:

      int count = QueryRunner.count(conn, sql, new Object[] { "foo", "bar" }

      );

      See attached diff.txt.

      Attachments

        1. ASF.LICENSE.NOT.GRANTED--count.java
          3 kB
          Michael Heuer
        2. ASF.LICENSE.NOT.GRANTED--count.java
          3 kB
          Michael Heuer
        3. ASF.LICENSE.NOT.GRANTED--diff.txt
          5 kB
          Michael Heuer

        Activity

          People

            Unassigned Unassigned
            heuermh@acm.org Michael Heuer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: