@ThreadSafe
public final class DbUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
close(java.sql.Connection conn)
Close a
Connection , avoid closing if null. |
static void |
close(java.sql.ResultSet rs)
Close a
ResultSet , avoid closing if null. |
static void |
close(java.sql.Statement stmt)
Close a
Statement , avoid closing if null. |
static void |
closeQuietly(java.sql.Connection conn)
Close a
Connection , avoid closing if null and hide
any SQLExceptions that occur. |
static void |
closeQuietly(java.sql.Connection conn,
java.sql.Statement stmt,
java.sql.ResultSet rs)
Close a
Connection , Statement and
ResultSet . |
static void |
closeQuietly(java.sql.ResultSet rs)
Close a
ResultSet , avoid closing if null and hide any
SQLExceptions that occur. |
static void |
closeQuietly(java.sql.Statement stmt)
Close a
Statement , avoid closing if null and hide
any SQLExceptions that occur. |
static void |
commitAndClose(java.sql.Connection conn)
Commits a
Connection then closes it, avoid closing if null. |
static void |
commitAndCloseQuietly(java.sql.Connection conn)
Commits a
Connection then closes it, avoid closing if null
and hide any SQLExceptions that occur. |
static boolean |
loadDriver(java.lang.String driverClassName)
Loads and registers a database driver class.
|
static void |
printStackTrace(java.sql.SQLException e)
Print the stack trace for a SQLException to STDERR.
|
static void |
printStackTrace(java.sql.SQLException e,
java.io.PrintWriter pw)
Print the stack trace for a SQLException to a
specified PrintWriter.
|
static void |
printWarnings(java.sql.Connection conn)
Print warnings on a Connection to STDERR.
|
static void |
printWarnings(java.sql.Connection conn,
java.io.PrintWriter pw)
Print warnings on a Connection to a specified PrintWriter.
|
static void |
rollback(java.sql.Connection conn)
Rollback any changes made on the given connection.
|
static void |
rollbackAndClose(java.sql.Connection conn)
Performs a rollback on the
Connection then closes it,
avoid closing if null. |
static void |
rollbackAndCloseQuietly(java.sql.Connection conn)
Performs a rollback on the
Connection then closes it,
avoid closing if null and hide any SQLExceptions that occur. |
public static void close(java.sql.Connection conn) throws java.sql.SQLException
Connection
, avoid closing if null.conn
- Connection to close.java.sql.SQLException
- if a database access error occurspublic static void close(@Nullable java.sql.ResultSet rs) throws java.sql.SQLException
ResultSet
, avoid closing if null.rs
- ResultSet to close.java.sql.SQLException
- if a database access error occurspublic static void close(@Nullable java.sql.Statement stmt) throws java.sql.SQLException
Statement
, avoid closing if null.stmt
- Statement to close.java.sql.SQLException
- if a database access error occurspublic static void closeQuietly(java.sql.Connection conn)
Connection
, avoid closing if null and hide
any SQLExceptions that occur.conn
- Connection to close.public static void closeQuietly(java.sql.Connection conn, java.sql.Statement stmt, java.sql.ResultSet rs)
Connection
, Statement
and
ResultSet
. Avoid closing if null and hide any
SQLExceptions that occur.conn
- Connection to close.stmt
- Statement to close.rs
- ResultSet to close.public static void closeQuietly(java.sql.ResultSet rs)
ResultSet
, avoid closing if null and hide any
SQLExceptions that occur.rs
- ResultSet to close.public static void closeQuietly(java.sql.Statement stmt)
Statement
, avoid closing if null and hide
any SQLExceptions that occur.stmt
- Statement to close.public static void commitAndClose(java.sql.Connection conn) throws java.sql.SQLException
Connection
then closes it, avoid closing if null.conn
- Connection to close.java.sql.SQLException
- if a database access error occurspublic static void commitAndCloseQuietly(java.sql.Connection conn)
Connection
then closes it, avoid closing if null
and hide any SQLExceptions that occur.conn
- Connection to close.public static boolean loadDriver(java.lang.String driverClassName)
driverClassName
- of driver to loadtrue
if the driver was found, otherwise false
public static void printStackTrace(java.sql.SQLException e)
e
- SQLException to print stack trace ofpublic static void printStackTrace(java.sql.SQLException e, java.io.PrintWriter pw)
e
- SQLException to print stack trace ofpw
- PrintWriter to print topublic static void printWarnings(java.sql.Connection conn)
conn
- Connection to print warnings frompublic static void printWarnings(java.sql.Connection conn, java.io.PrintWriter pw)
conn
- Connection to print warnings frompw
- PrintWriter to print topublic static void rollback(java.sql.Connection conn) throws java.sql.SQLException
conn
- Connection to rollback. A null value is legal.java.sql.SQLException
- if a database access error occurspublic static void rollbackAndClose(java.sql.Connection conn) throws java.sql.SQLException
Connection
then closes it,
avoid closing if null.conn
- Connection to rollback. A null value is legal.java.sql.SQLException
- if a database access error occurspublic static void rollbackAndCloseQuietly(java.sql.Connection conn)
Connection
then closes it,
avoid closing if null and hide any SQLExceptions that occur.conn
- Connection to rollback. A null value is legal.