Package org.apache.commons.dbutils
Class DbUtils
- java.lang.Object
-
- org.apache.commons.dbutils.DbUtils
-
-
Constructor Summary
Constructors Constructor Description DbUtils()Default constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(Connection conn)Close aConnection, avoid closing if null.static voidclose(ResultSet resultSet)Close aResultSet, avoid closing if null.static voidclose(Statement stmt)Close aStatement, avoid closing if null.static voidcloseQuietly(Connection conn)Close aConnection, avoid closing if null and hide any SQLExceptions that occur.static voidcloseQuietly(Connection conn, Statement stmt, ResultSet rs)Close aConnection,StatementandResultSet.static voidcloseQuietly(ResultSet resultSet)Close aResultSet, avoid closing if null and hide any SQLExceptions that occur.static voidcloseQuietly(Statement stmt)Close aStatement, avoid closing if null and hide any SQLExceptions that occur.static voidcommitAndClose(Connection conn)Commits aConnectionthen closes it, avoid closing if null.static voidcommitAndCloseQuietly(Connection conn)Commits aConnectionthen closes it, avoid closing if null and hide any SQLExceptions that occur.static booleanloadDriver(ClassLoader classLoader, String driverClassName)Loads and registers a database driver class.static booleanloadDriver(String driverClassName)Loads and registers a database driver class.static voidprintStackTrace(SQLException e)Print the stack trace for a SQLException to STDERR.static voidprintStackTrace(SQLException e, PrintWriter pw)Print the stack trace for a SQLException to a specified PrintWriter.static voidprintWarnings(Connection conn)Print warnings on a Connection to STDERR.static voidprintWarnings(Connection conn, PrintWriter pw)Print warnings on a Connection to a specified PrintWriter.static voidrollback(Connection conn)Rollback any changes made on the given connection.static voidrollbackAndClose(Connection conn)Performs a rollback on theConnectionthen closes it, avoid closing if null.static voidrollbackAndCloseQuietly(Connection conn)Performs a rollback on theConnectionthen closes it, avoid closing if null and hide any SQLExceptions that occur.static voidrollbackQuietly(Connection conn)Performs a rollback on theConnection, avoid closing if null and hide any SQLExceptions that occur.
-
-
-
Constructor Detail
-
DbUtils
public DbUtils()
Default constructor. Utility classes should not have a public or default constructor, but this one preserves retro-compatibility.- Since:
- 1.4
-
-
Method Detail
-
close
public static void close(Connection conn) throws SQLException
Close aConnection, avoid closing if null.- Parameters:
conn- Connection to close.- Throws:
SQLException- if a database access error occurs
-
close
public static void close(ResultSet resultSet) throws SQLException
Close aResultSet, avoid closing if null.- Parameters:
resultSet- ResultSet to close.- Throws:
SQLException- if a database access error occurs
-
close
public static void close(Statement stmt) throws SQLException
Close aStatement, avoid closing if null.- Parameters:
stmt- Statement to close.- Throws:
SQLException- if a database access error occurs
-
closeQuietly
public static void closeQuietly(Connection conn)
Close aConnection, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
conn- Connection to close.
-
closeQuietly
public static void closeQuietly(Connection conn, Statement stmt, 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(ResultSet resultSet)
Close aResultSet, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
resultSet- ResultSet to close.
-
closeQuietly
public static void closeQuietly(Statement stmt)
Close aStatement, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
stmt- Statement to close.
-
commitAndClose
public static void commitAndClose(Connection conn) throws SQLException
Commits aConnectionthen closes it, avoid closing if null.- Parameters:
conn- Connection to close.- Throws:
SQLException- if a database access error occurs
-
commitAndCloseQuietly
public static void commitAndCloseQuietly(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(ClassLoader classLoader, 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
-
loadDriver
public static boolean loadDriver(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
-
printStackTrace
public static void printStackTrace(SQLException e)
Print the stack trace for a SQLException to STDERR.- Parameters:
e- SQLException to print stack trace of
-
printStackTrace
public static void printStackTrace(SQLException e, 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(Connection conn)
Print warnings on a Connection to STDERR.- Parameters:
conn- Connection to print warnings from
-
printWarnings
public static void printWarnings(Connection conn, 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(Connection conn) throws SQLException
Rollback any changes made on the given connection.- Parameters:
conn- Connection to rollback. A null value is legal.- Throws:
SQLException- if a database access error occurs
-
rollbackAndClose
public static void rollbackAndClose(Connection conn) throws SQLException
Performs a rollback on theConnectionthen closes it, avoid closing if null.- Parameters:
conn- Connection to rollback. A null value is legal.- Throws:
SQLException- if a database access error occurs- Since:
- 1.1
-
rollbackAndCloseQuietly
public static void rollbackAndCloseQuietly(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:
- 1.1
-
rollbackQuietly
public static void rollbackQuietly(Connection conn)
Performs a rollback on theConnection, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
conn- Connection to rollback. A null value is legal.- Since:
- DbUtils 2.0
-
-