Package org.apache.commons.dbutils
Class DbUtils
- java.lang.Object
-
- org.apache.commons.dbutils.DbUtils
-
public final class DbUtils extends java.lang.ObjectA collection of JDBC helper methods. This class is thread safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classDbUtils.DriverProxySimpleDriverproxy class that proxies a JDBC Driver loaded dynamically.
-
Constructor Summary
Constructors Constructor Description DbUtils()Default constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(java.sql.Connection conn)Close aConnection, avoid closing if null.static voidclose(java.sql.ResultSet rs)Close aResultSet, avoid closing if null.static voidclose(java.sql.Statement stmt)Close aStatement, avoid closing if null.static voidcloseQuietly(java.sql.Connection conn)Close aConnection, avoid closing if null and hide any SQLExceptions that occur.static voidcloseQuietly(java.sql.Connection conn, java.sql.Statement stmt, java.sql.ResultSet rs)Close aConnection,StatementandResultSet.static voidcloseQuietly(java.sql.ResultSet rs)Close aResultSet, avoid closing if null and hide any SQLExceptions that occur.static voidcloseQuietly(java.sql.Statement stmt)Close aStatement, avoid closing if null and hide any SQLExceptions that occur.static voidcommitAndClose(java.sql.Connection conn)Commits aConnectionthen closes it, avoid closing if null.static voidcommitAndCloseQuietly(java.sql.Connection conn)Commits aConnectionthen closes it, avoid closing if null and hide any SQLExceptions that occur.static booleanloadDriver(java.lang.ClassLoader classLoader, java.lang.String driverClassName)Loads and registers a database driver class.static booleanloadDriver(java.lang.String driverClassName)Loads and registers a database driver class.static voidprintStackTrace(java.sql.SQLException e)Print the stack trace for a SQLException to STDERR.static voidprintStackTrace(java.sql.SQLException e, java.io.PrintWriter pw)Print the stack trace for a SQLException to a specified PrintWriter.static voidprintWarnings(java.sql.Connection conn)Print warnings on a Connection to STDERR.static voidprintWarnings(java.sql.Connection conn, java.io.PrintWriter pw)Print warnings on a Connection to a specified PrintWriter.static voidrollback(java.sql.Connection conn)Rollback any changes made on the given connection.static voidrollbackAndClose(java.sql.Connection conn)Performs a rollback on theConnectionthen closes it, avoid closing if null.static voidrollbackAndCloseQuietly(java.sql.Connection conn)Performs a rollback on theConnectionthen closes it, avoid closing if null and hide any SQLExceptions that occur.
-
-
-
Method Detail
-
close
public static void close(java.sql.Connection conn) throws java.sql.SQLExceptionClose aConnection, avoid closing if null.- Parameters:
conn- Connection to close.- Throws:
java.sql.SQLException- if a database access error occurs
-
close
public static void close(java.sql.ResultSet rs) throws java.sql.SQLExceptionClose aResultSet, avoid closing if null.- Parameters:
rs- ResultSet to close.- Throws:
java.sql.SQLException- if a database access error occurs
-
close
public static void close(java.sql.Statement stmt) throws java.sql.SQLExceptionClose aStatement, avoid closing if null.- Parameters:
stmt- Statement to close.- Throws:
java.sql.SQLException- if a database access error occurs
-
closeQuietly
public static void closeQuietly(java.sql.Connection conn)
Close aConnection, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
conn- Connection to close.
-
closeQuietly
public static void closeQuietly(java.sql.Connection conn, java.sql.Statement stmt, java.sql.ResultSet rs)Close aConnection,StatementandResultSet. Avoid closing if null and hide any SQLExceptions that occur.- Parameters:
conn- Connection to close.stmt- Statement to close.rs- ResultSet to close.
-
closeQuietly
public static void closeQuietly(java.sql.ResultSet rs)
Close aResultSet, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
rs- ResultSet to close.
-
closeQuietly
public static void closeQuietly(java.sql.Statement stmt)
Close aStatement, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
stmt- Statement to close.
-
commitAndClose
public static void commitAndClose(java.sql.Connection conn) throws java.sql.SQLExceptionCommits aConnectionthen closes it, avoid closing if null.- Parameters:
conn- Connection to close.- Throws:
java.sql.SQLException- if a database access error occurs
-
commitAndCloseQuietly
public static void commitAndCloseQuietly(java.sql.Connection conn)
Commits aConnectionthen closes it, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
conn- Connection to close.
-
loadDriver
public static boolean loadDriver(java.lang.String driverClassName)
Loads and registers a database driver class. If this succeeds, it returns true, else it returns false.- Parameters:
driverClassName- of driver to load- Returns:
- boolean
trueif the driver was found, otherwisefalse
-
loadDriver
public static boolean loadDriver(java.lang.ClassLoader classLoader, java.lang.String driverClassName)Loads and registers a database driver class. If this succeeds, it returns true, else it returns false.- Parameters:
classLoader- the class loader used to load the driver classdriverClassName- of driver to load- Returns:
- boolean
trueif the driver was found, otherwisefalse - Since:
- 1.4
-
printStackTrace
public static void printStackTrace(java.sql.SQLException e)
Print the stack trace for a SQLException to STDERR.- Parameters:
e- SQLException to print stack trace of
-
printStackTrace
public static void printStackTrace(java.sql.SQLException e, java.io.PrintWriter pw)Print the stack trace for a SQLException to a specified PrintWriter.- Parameters:
e- SQLException to print stack trace ofpw- PrintWriter to print to
-
printWarnings
public static void printWarnings(java.sql.Connection conn)
Print warnings on a Connection to STDERR.- Parameters:
conn- Connection to print warnings from
-
printWarnings
public static void printWarnings(java.sql.Connection conn, java.io.PrintWriter pw)Print warnings on a Connection to a specified PrintWriter.- Parameters:
conn- Connection to print warnings frompw- PrintWriter to print to
-
rollback
public static void rollback(java.sql.Connection conn) throws java.sql.SQLExceptionRollback any changes made on the given connection.- Parameters:
conn- Connection to rollback. A null value is legal.- Throws:
java.sql.SQLException- if a database access error occurs
-
rollbackAndClose
public static void rollbackAndClose(java.sql.Connection conn) throws java.sql.SQLExceptionPerforms a rollback on theConnectionthen closes it, avoid closing if null.- Parameters:
conn- Connection to rollback. A null value is legal.- Throws:
java.sql.SQLException- if a database access error occurs- Since:
- DbUtils 1.1
-
rollbackAndCloseQuietly
public static void rollbackAndCloseQuietly(java.sql.Connection conn)
Performs a rollback on theConnectionthen closes it, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
conn- Connection to rollback. A null value is legal.- Since:
- DbUtils 1.1
-
-