|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.dbutils.DbUtils
public final class DbUtils
A collection of JDBC helper methods. This class is thread safe.
Constructor Summary | |
---|---|
DbUtils()
Default constructor. |
Method Summary | |
---|---|
static void |
close(Connection conn)
Close a Connection , avoid closing if null. |
static void |
close(ResultSet rs)
Close a ResultSet , avoid closing if null. |
static void |
close(Statement stmt)
Close a Statement , avoid closing if null. |
static void |
closeQuietly(Connection conn)
Close a Connection , avoid closing if null and hide
any SQLExceptions that occur. |
static void |
closeQuietly(Connection conn,
Statement stmt,
ResultSet rs)
Close a Connection , Statement and
ResultSet . |
static void |
closeQuietly(ResultSet rs)
Close a ResultSet , avoid closing if null and hide any
SQLExceptions that occur. |
static void |
closeQuietly(Statement stmt)
Close a Statement , avoid closing if null and hide
any SQLExceptions that occur. |
static void |
commitAndClose(Connection conn)
Commits a Connection then closes it, avoid closing if null. |
static void |
commitAndCloseQuietly(Connection conn)
Commits a Connection then closes it, avoid closing if null
and hide any SQLExceptions that occur. |
static boolean |
loadDriver(ClassLoader classLoader,
String driverClassName)
Loads and registers a database driver class. |
static boolean |
loadDriver(String driverClassName)
Loads and registers a database driver class. |
static void |
printStackTrace(SQLException e)
Print the stack trace for a SQLException to STDERR. |
static void |
printStackTrace(SQLException e,
PrintWriter pw)
Print the stack trace for a SQLException to a specified PrintWriter. |
static void |
printWarnings(Connection conn)
Print warnings on a Connection to STDERR. |
static void |
printWarnings(Connection conn,
PrintWriter pw)
Print warnings on a Connection to a specified PrintWriter. |
static void |
rollback(Connection conn)
Rollback any changes made on the given connection. |
static void |
rollbackAndClose(Connection conn)
Performs a rollback on the Connection then closes it,
avoid closing if null. |
static void |
rollbackAndCloseQuietly(Connection conn)
Performs a rollback on the Connection then closes it,
avoid closing if null and hide any SQLExceptions that occur. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DbUtils()
Method Detail |
---|
public static void close(Connection conn) throws SQLException
Connection
, avoid closing if null.
conn
- Connection to close.
SQLException
- if a database access error occurspublic static void close(ResultSet rs) throws SQLException
ResultSet
, avoid closing if null.
rs
- ResultSet to close.
SQLException
- if a database access error occurspublic static void close(Statement stmt) throws SQLException
Statement
, avoid closing if null.
stmt
- Statement to close.
SQLException
- if a database access error occurspublic static void closeQuietly(Connection conn)
Connection
, avoid closing if null and hide
any SQLExceptions that occur.
conn
- Connection to close.public static void closeQuietly(Connection conn, Statement stmt, 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(ResultSet rs)
ResultSet
, avoid closing if null and hide any
SQLExceptions that occur.
rs
- ResultSet to close.public static void closeQuietly(Statement stmt)
Statement
, avoid closing if null and hide
any SQLExceptions that occur.
stmt
- Statement to close.public static void commitAndClose(Connection conn) throws SQLException
Connection
then closes it, avoid closing if null.
conn
- Connection to close.
SQLException
- if a database access error occurspublic static void commitAndCloseQuietly(Connection conn)
Connection
then closes it, avoid closing if null
and hide any SQLExceptions that occur.
conn
- Connection to close.public static boolean loadDriver(String driverClassName)
driverClassName
- of driver to load
true
if the driver was found, otherwise false
public static boolean loadDriver(ClassLoader classLoader, String driverClassName)
classLoader
- the class loader used to load the driver classdriverClassName
- of driver to load
true
if the driver was found, otherwise false
public static void printStackTrace(SQLException e)
e
- SQLException to print stack trace ofpublic static void printStackTrace(SQLException e, PrintWriter pw)
e
- SQLException to print stack trace ofpw
- PrintWriter to print topublic static void printWarnings(Connection conn)
conn
- Connection to print warnings frompublic static void printWarnings(Connection conn, PrintWriter pw)
conn
- Connection to print warnings frompw
- PrintWriter to print topublic static void rollback(Connection conn) throws SQLException
conn
- Connection to rollback. A null value is legal.
SQLException
- if a database access error occurspublic static void rollbackAndClose(Connection conn) throws SQLException
Connection
then closes it,
avoid closing if null.
conn
- Connection to rollback. A null value is legal.
SQLException
- if a database access error occurspublic static void rollbackAndCloseQuietly(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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |