public class JDBCUtil extends Object
| Constructor and Description |
|---|
JDBCUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
closeQuietly(Connection cxt)
Closes the passed
Connection ignoring exceptions. |
static void |
closeQuietly(ResultSet rslt)
Closes the passed
ResultSet ignoring exceptions. |
static void |
closeQuietly(Statement stmt)
Closes the passed
ResultSet ignoring exceptions. |
static List<Map<String,Object>> |
executeQuery(Connection cxt,
String sql,
Object... args)
Executes a query and returns the results, ensuring that the created statement
and resultset are closed.
|
static int |
executeUpdate(Connection cxt,
String sql,
Object... args)
Executes an update and returns the results, ensuring that the created statement is closed.
|
static PreparedStatement |
prepare(Connection cxt,
String sql,
Object... args)
Creates a
PreparedStatement from the provided connection. |
static List<Map<String,Object>> |
retrieve(ResultSet rslt)
Iterates through the passed
ResultSet, converting each row into a
Map, where keys are the column names as retrieved from metadata,
and values are the result of calling getObject(). |
public static List<Map<String,Object>> executeQuery(Connection cxt, String sql, Object... args) throws SQLException
args - Parameters for the query. May be empty.SQLExceptionpublic static int executeUpdate(Connection cxt, String sql, Object... args) throws SQLException
args - Parameters for the query. May be empty.SQLExceptionpublic static PreparedStatement prepare(Connection cxt, String sql, Object... args) throws SQLException
PreparedStatement from the provided connection.args - Parameters for the query. May be empty.SQLExceptionpublic static List<Map<String,Object>> retrieve(ResultSet rslt) throws SQLException
ResultSet, converting each row into a
Map, where keys are the column names as retrieved from metadata,
and values are the result of calling getObject().
Caller is responsible for closing the ResultSet.
SQLExceptionpublic static void closeQuietly(Connection cxt)
Connection ignoring exceptions. This is usually
called in a finally block, and throwing an exception there would
overwrite any exception thrown by the main code (and if there is an exception
when closing, there probably was one there as well).public static void closeQuietly(Statement stmt)
ResultSet ignoring exceptions. This is usually
called in a finally block, and throwing an exception there would
overwrite any exception thrown by the main code (and if there is an exception
when closing, there probably was one there as well).public static void closeQuietly(ResultSet rslt)
ResultSet ignoring exceptions. This is usually
called in a finally block, and throwing an exception there would
overwrite any exception thrown by the main code (and if there is an exception
when closing, there probably was one there as well).