Package org.conical.common.bbl.db
Class DbUtil
java.lang.Object
org.conical.common.bbl.db.DbUtil
Defines a set of static database utility methods
- Author:
- rdoherty
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Quietly closes an array of Wrapper objects.static int
executeSingleIntResultQuery
(Connection conn, String sql) Executes a give SQL query on the given connection and returns a single integer result.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.static int
getNextSequenceValue
(Connection conn, String sequenceName) Returns the next value in the named sequence given the passed connection.static Date
getSqlDate
(Date date) Converts a java.util.Date to a java.sql.Date.
-
Constructor Details
-
DbUtil
public DbUtil()
-
-
Method Details
-
close
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
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 usesequenceName
- name of the sequence from which to get the nexty value- Returns:
- next value in the sequence
-
executeSingleIntResultQuery
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 usesql
- 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 innoResultsErrorMsg
. If a SQL exception occurs (e.g. bad query, first resulting column is not an integer), an exception will be thrown containing the text insqlExceptionErrorMsg
.- Parameters:
conn
- connection to usesql
- sql to executenoResultsErrorMsg
- text in exception if no results are returnedsqlExceptionErrorMsg
- text in exception if SQLException occurs- Returns:
- a single result
-
getSqlDate
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
-