Class DbUtil

java.lang.Object
org.conical.common.bbl.db.DbUtil

public class DbUtil extends Object
Defines a set of static database utility methods
Author:
rdoherty
  • Constructor Details

    • DbUtil

      public DbUtil()
  • Method Details

    • close

      public static void close(Wrapper... wrappers)
      Quietly closes an array of Wrapper objects. Currently the following classes are supported (all other classes, nulls, and already-closed objects are ignored):
      • java.sql.Connection
      • java.sql.Statement
      • java.sql.PreparedStatement
      • java.sql.ResultSet
      Parameters:
      wrappers - array of wrappers to close
    • getNextSequenceValue

      public static int getNextSequenceValue(Connection conn, String sequenceName)
      Returns the next value in the named sequence given the passed connection. The SQL generated for this query assumes Oracle as the DB server.
      Parameters:
      conn - connection to use
      sequenceName - name of the sequence from which to get the nexty value
      Returns:
      next value in the sequence
    • executeSingleIntResultQuery

      public static int executeSingleIntResultQuery(Connection conn, String sql)
      Executes a give SQL query on the given connection and returns a single integer result. This method ignores results beyond the first column and beyond the first returned row. If no results are returned or a SQL exception occurs (e.g. bad query, first resulting column is not an integer), an exception will be thrown with a default message.
      Parameters:
      conn - connection to use
      sql - sql to execute
      Returns:
      a single result
    • executeSingleIntResultQuery

      public static int executeSingleIntResultQuery(Connection conn, String sql, String noResultsErrorMsg, String sqlExceptionErrorMsg)
      Executes a give SQL query on the given connection and returns a single integer result. This method ignores results beyond the first column and beyond the first returned row. If no results are returned, an exception will be thrown containing the text in noResultsErrorMsg. If a SQL exception occurs (e.g. bad query, first resulting column is not an integer), an exception will be thrown containing the text in sqlExceptionErrorMsg.
      Parameters:
      conn - connection to use
      sql - sql to execute
      noResultsErrorMsg - text in exception if no results are returned
      sqlExceptionErrorMsg - text in exception if SQLException occurs
      Returns:
      a single result
    • getSqlDate

      public static Date getSqlDate(Date date)
      Converts a java.util.Date to a java.sql.Date. If the date passed is null, null will be returned.
      Parameters:
      date - date to convert
      Returns:
      new date, or null