org.cementj.util
Class DatabaseUtility

java.lang.Object
  extended by org.cementj.util.DatabaseUtility
Direct Known Subclasses:
DatabaseUtility

public class DatabaseUtility
extends java.lang.Object

A collection of database oriented utilities.

Copyright: Delta Vortex Technologies, 2002.


Field Summary
static java.lang.String ORACLE_TYPE4_DRIVER
           
static java.lang.String SYBASE_JDBC_DRIVER_NAME
           
 
Constructor Summary
protected DatabaseUtility()
          Constructor
 
Method Summary
static void close(java.sql.CallableStatement cStmt)
          Closes a callable statement logging a warning if a SQLException is encountered.
static void close(java.sql.Connection conn)
          Closes a database Connection logging a warning if a SQLException is encountered.
static void close(java.lang.Object dbObj)
          Closes a JDBC-related object logging a warning if a SQLException is encountered.
static void close(java.lang.Object dbObj1, java.lang.Object dbObj2)
          Closes JDBC-related objects in the order provided logging a warning if a SQLException is encountered.
static void close(java.lang.Object dbObj1, java.lang.Object dbObj2, java.lang.Object dbObj3)
          Closes JDBC-related objects in the order provided logging a warning if a SQLException is encountered.
static void close(java.lang.Object dbObj1, java.lang.Object dbObj2, java.lang.Object dbObj3, java.lang.Object dbObj4)
          Closes JDBC-related objects in the order provided logging a warning if a SQLException is encountered.
static void close(java.lang.Object dbObj1, java.lang.Object dbObj2, java.lang.Object dbObj3, java.lang.Object dbObj4, java.lang.Object dbObj5)
          Closes JDBC-related objects in the order provided logging a warning if a SQLException is encountered.
static void close(java.sql.PreparedStatement pStmt)
          Closes a prepared statement logging a warning if a SQLException is encountered.
static void close(java.sql.ResultSet rs)
          Closes a result set logging a warning if a SQLException is encountered.
static void close(java.sql.Statement stmt)
          Closes a statement logging a warning if a SQLException is encountered.
static java.util.Date convertTimestampToUtilDate(java.sql.Timestamp ts)
          Converts a java.sql.Timestamp to a java.util.Date.
static java.sql.Timestamp convertUtilDateToTimestamp(java.util.Date date)
          Converts a java.util.Date to a java.sql.Timestamp.
static java.sql.Timestamp getCurrentTimestamp()
          Provides a java.sql.Timestamp set to the current ssytem time.
static java.sql.Connection getJDBCConnection(java.lang.String driverName, java.lang.String connectString)
          Generic utility that returns a database connection using a given driver.
static java.sql.Connection getJDBCConnection(java.lang.String driverName, java.lang.String connectString, java.lang.String dbUserID, java.lang.String password)
          Provides a JDBC connection given a DriverManager class name, connect string, userid, and password.
static java.sql.Connection getOracleJDBCConnection(java.lang.String serverName, int port, java.lang.String dbInstance, java.lang.String dbUserID, java.lang.String password)
          This returns an Oracle JDBC Connection based on the connection string, user id and password given.
static java.sql.ResultSet getSerializableResultSet(java.sql.ResultSet inputResultSet)
          Converts a ResultSet into a serializable version that can be returned to remote clients.
static java.sql.Connection getSybaseConnection(java.lang.String server, int port, java.lang.String userId, java.lang.String password)
          Provides a Sybase database connection using the Sybase-provided driver com.sybase.jdbc2.jdbc.SybDriver.
static void rollback(java.sql.Connection dbConnection)
          Rolls back a dataabse transaction logging a warning if a SQLException is encountered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORACLE_TYPE4_DRIVER

public static final java.lang.String ORACLE_TYPE4_DRIVER
See Also:
Constant Field Values

SYBASE_JDBC_DRIVER_NAME

public static final java.lang.String SYBASE_JDBC_DRIVER_NAME
See Also:
Constant Field Values
Constructor Detail

DatabaseUtility

protected DatabaseUtility()
Constructor

Method Detail

close

public static void close(java.sql.PreparedStatement pStmt)
Closes a prepared statement logging a warning if a SQLException is encountered.

Use of this version of close eliminates the need for verbose try/catch logic to handle the SQLException.

Since:
0.5

close

public static void close(java.sql.Statement stmt)
Closes a statement logging a warning if a SQLException is encountered.

Use of this version of close eliminates the need for verbose try/catch logic to handle the SQLException.

Since:
0.5

close

public static void close(java.sql.CallableStatement cStmt)
Closes a callable statement logging a warning if a SQLException is encountered.

Use of this version of close eliminates the need for verbose try/catch logic to handle the SQLException.

Since:
0.5

close

public static void close(java.sql.ResultSet rs)
Closes a result set logging a warning if a SQLException is encountered.

Use of this version of close eliminates the need for verbose try/catch logic to handle the SQLException.

Since:
0.5

close

public static void close(java.sql.Connection conn)
Closes a database Connection logging a warning if a SQLException is encountered.

Use of this version of close eliminates the need for verbose try/catch logic to handle the SQLException.

Since:
0.5

close

public static void close(java.lang.Object dbObj)
Closes a JDBC-related object logging a warning if a SQLException is encountered.

Use of this version of close eliminates the need for verbose try/catch logic to handle the SQLException.

This method will generate an IllegalArgumentException if the object passed isn't one of the following classes in java.sql: PreparedStatement, Statement, ResultSet, CallableStatement, or Connection.

Since:
0.5

close

public static void close(java.lang.Object dbObj1,
                         java.lang.Object dbObj2)
Closes JDBC-related objects in the order provided logging a warning if a SQLException is encountered.

Use of this version of close eliminates the need for verbose try/catch logic to handle the SQLException.

This method will generate an IllegalArgumentException if the object passed isn't one of the following classes in java.sql: PreparedStatement, Statement, ResultSet, CallableStatement, or Connection.

Objects will be closed in the order listed.

Since:
0.5

close

public static void close(java.lang.Object dbObj1,
                         java.lang.Object dbObj2,
                         java.lang.Object dbObj3)
Closes JDBC-related objects in the order provided logging a warning if a SQLException is encountered.

Use of this version of close eliminates the need for verbose try/catch logic to handle the SQLException.

This method will generate an IllegalArgumentException if the object passed isn't one of the following classes in java.sql: PreparedStatement, Statement, ResultSet, CallableStatement, or Connection.

Objects will be closed in the order listed.

Since:
0.5

close

public static void close(java.lang.Object dbObj1,
                         java.lang.Object dbObj2,
                         java.lang.Object dbObj3,
                         java.lang.Object dbObj4)
Closes JDBC-related objects in the order provided logging a warning if a SQLException is encountered.

Use of this version of close eliminates the need for verbose try/catch logic to handle the SQLException.

This method will generate an IllegalArgumentException if the object passed isn't one of the following classes in java.sql: PreparedStatement, Statement, ResultSet, CallableStatement, or Connection.

Objects will be closed in the order listed.

Since:
0.5

close

public static void close(java.lang.Object dbObj1,
                         java.lang.Object dbObj2,
                         java.lang.Object dbObj3,
                         java.lang.Object dbObj4,
                         java.lang.Object dbObj5)
Closes JDBC-related objects in the order provided logging a warning if a SQLException is encountered.

Use of this version of close eliminates the need for verbose try/catch logic to handle the SQLException.

This method will generate an IllegalArgumentException if the object passed isn't one of the following classes in java.sql: PreparedStatement, Statement, ResultSet, CallableStatement, or Connection.

Objects will be closed in the order listed.

Since:
0.5

convertTimestampToUtilDate

public static java.util.Date convertTimestampToUtilDate(java.sql.Timestamp ts)
Converts a java.sql.Timestamp to a java.util.Date.

Null arguments generate an IllegalArgumentException.

Parameters:
Timestamp -
Returns:
Date
Since:
0.5

convertUtilDateToTimestamp

public static java.sql.Timestamp convertUtilDateToTimestamp(java.util.Date date)
Converts a java.util.Date to a java.sql.Timestamp.

Null arguments generate an IllegalArgumentException.

Parameters:
Date -
Returns:
Timestamp
Since:
0.5

getCurrentTimestamp

public static java.sql.Timestamp getCurrentTimestamp()
Provides a java.sql.Timestamp set to the current ssytem time.

Returns:
Timestamp Current
Since:
0.5

getSybaseConnection

public static java.sql.Connection getSybaseConnection(java.lang.String server,
                                                      int port,
                                                      java.lang.String userId,
                                                      java.lang.String password)
                                               throws java.sql.SQLException,
                                                      java.lang.ClassNotFoundException,
                                                      java.lang.IllegalAccessException,
                                                      java.lang.InstantiationException
Provides a Sybase database connection using the Sybase-provided driver com.sybase.jdbc2.jdbc.SybDriver. This method does require that the Sybase JDBC driver be in the classpath.

The Sybase database driver is not provided with CementJ. You need to download and install the Sybase JDBC driver from Sybase at www.sybase.com.

Throws:
java.sql.SQLException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
Since:
0.5

getOracleJDBCConnection

public static java.sql.Connection getOracleJDBCConnection(java.lang.String serverName,
                                                          int port,
                                                          java.lang.String dbInstance,
                                                          java.lang.String dbUserID,
                                                          java.lang.String password)
                                                   throws java.lang.ClassNotFoundException,
                                                          java.lang.IllegalAccessException,
                                                          java.lang.InstantiationException,
                                                          java.sql.SQLException
This returns an Oracle JDBC Connection based on the connection string, user id and password given.

The Oracle database driver is not provided with CementJ. You need to download and install the Oracle JDBC driver from Oracle Corporation at otn.oracle.com.

Throws:
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.sql.SQLException
Since:
0.5

getJDBCConnection

public static java.sql.Connection getJDBCConnection(java.lang.String driverName,
                                                    java.lang.String connectString,
                                                    java.lang.String dbUserID,
                                                    java.lang.String password)
                                             throws java.lang.ClassNotFoundException,
                                                    java.lang.IllegalAccessException,
                                                    java.lang.InstantiationException,
                                                    java.sql.SQLException
Provides a JDBC connection given a DriverManager class name, connect string, userid, and password.

Throws:
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.sql.SQLException
Since:
0.5

getJDBCConnection

public static java.sql.Connection getJDBCConnection(java.lang.String driverName,
                                                    java.lang.String connectString)
                                             throws java.lang.ClassNotFoundException,
                                                    java.lang.IllegalAccessException,
                                                    java.lang.InstantiationException,
                                                    java.sql.SQLException
Generic utility that returns a database connection using a given driver.

Parameters:
driverName -
connectString -
Returns:
Connection
Throws:
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.sql.SQLException

rollback

public static void rollback(java.sql.Connection dbConnection)
Rolls back a dataabse transaction logging a warning if a SQLException is encountered.

Use of this version of rollback eliminates the need for verbose try/catch logic to handle the SQLException.

Since:
0.5

getSerializableResultSet

public static java.sql.ResultSet getSerializableResultSet(java.sql.ResultSet inputResultSet)
                                                   throws java.sql.SQLException
Converts a ResultSet into a serializable version that can be returned to remote clients.

Throws:
java.sql.SQLException
Since:
0.5


Copyright © 2003 Delta Vortex Technologies, Inc. All Rights Reserved.