org.apache.commons.dbutils
Class DbUtils

java.lang.Object
  extended byorg.apache.commons.dbutils.DbUtils

public final class DbUtils
extends Object

A collection of JDBC helper methods. This class is thread safe.

Author:
Henri Yandell, Juozas Baliuka, Steven Caswell, David Graham

Constructor Summary
DbUtils()
           
 
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(String driverClassName)
          Loads and registers a database driver class.
static void printStackTrace(SQLException sqle)
           
static void printStackTrace(SQLException sqle, PrintWriter pw)
           
static void printWarnings(Connection connection)
           
static void printWarnings(Connection conn, PrintWriter pw)
           
static void rollback(Connection conn)
          Rollback any changes made on the given connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbUtils

public DbUtils()
Method Detail

close

public static void close(Connection conn)
                  throws SQLException
Close a Connection, avoid closing if null.

Throws:
SQLException

close

public static void close(ResultSet rs)
                  throws SQLException
Close a ResultSet, avoid closing if null.

Throws:
SQLException

close

public static void close(Statement stmt)
                  throws SQLException
Close a Statement, avoid closing if null.

Throws:
SQLException

closeQuietly

public static void closeQuietly(Connection conn)
Close a Connection, avoid closing if null and hide any SQLExceptions that occur.


closeQuietly

public static void closeQuietly(Connection conn,
                                Statement stmt,
                                ResultSet rs)
Close a Connection, Statement and ResultSet. Avoid closing if null and hide any SQLExceptions that occur.


closeQuietly

public static void closeQuietly(ResultSet rs)
Close a ResultSet, avoid closing if null and hide any SQLExceptions that occur.


closeQuietly

public static void closeQuietly(Statement stmt)
Close a Statement, avoid closing if null and hide any SQLExceptions that occur.


commitAndClose

public static void commitAndClose(Connection conn)
                           throws SQLException
Commits a Connection then closes it, avoid closing if null.

Throws:
SQLException

commitAndCloseQuietly

public static void commitAndCloseQuietly(Connection conn)
Commits a Connection then closes it, avoid closing if null and hide any SQLExceptions that occur.


loadDriver

public static boolean loadDriver(String driverClassName)
Loads and registers a database driver class. If this succeeds, it returns true, else it returns false.


printStackTrace

public static void printStackTrace(SQLException sqle)

printStackTrace

public static void printStackTrace(SQLException sqle,
                                   PrintWriter pw)

printWarnings

public static void printWarnings(Connection connection)

printWarnings

public static void printWarnings(Connection conn,
                                 PrintWriter pw)

rollback

public static void rollback(Connection conn)
                     throws SQLException
Rollback any changes made on the given connection.

Parameters:
conn - The database Connection to rollback. A null value is legal.
Throws:
SQLException