JdbcHelper Class

com.bea.p13n.util.jdbc
JdbcHelper Class

public class JdbcHelper

    extends Object

See also the Database and DatabaseFactory classes.


Hierarchy
Object
  JdbcHelper

Method Summary

public static void
close(Connection con)
Close a connection, ignoring any errors.
public static void
close(Statement stmt)
Close a statement, ignoring any errors.
public static void
close(ResultSet rs)
Close a result set, ignoring any errors.
public static void
close(ResultSet rs, Statement stmt, Connection con)
Close a connection, statement and resultset, ignoring errors.
public static void
commitConnection(Connection con)
Commits the java.sql.Connection that you have been using for CLOB operations.
public static String
getClob(ResultSet rs, int index)
Get the value of a CLOB column as a string.
public static Clob
getClobLocator(Connection con, String tableName, String clobColumnName, String whereClause)
Retrieve the LOB locator for a CLOB.
public static Connection
getConnection(DataSource src, int retries, long waitTime)
Get a connection from a DataSource.
public static Connection
getConnection(DataSource src, int retries)
Get a connection from a DataSource.
public static String
getEmptyClobInitializer()
Return the database specific keyword that must be used when inserting a row with an empty CLOB.
public static JdbcHelper
getInstance()
public static void
resumeTransaction(Transaction suspendedTransaction)
Resumes the suspended transaction if it is not null.
public static void
setClob(PreparedStatement stmt, int index, String str)
Set the value of a CLOB column with a string.
public static boolean
setClob(PreparedStatement stmt, int index, Clob clob, String str)
If there is a delegate, this method uses JdbcHelperDelegate.writeClobData() If this is done, then the PreparedStatement does not need to be used and the return value, executeRequired, is false.
public static void
setJdbcHelperDelegate(String className)
public static String
showIsolationLevel(Connection connection)
Show transaction isolation level of connection
public static UserTransaction
startTransaction()
Start a new transaction
public static Transaction
suspendTransaction()
Suspend any current transaction (unless suspendTransaction is false).
 
Methods from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
   

Method Detail

close(Connection) Method

public static void close(Connection con)
Close a connection, ignoring any errors.

Parameters

con
The Connection object to be closed.

close(Statement) Method

public static void close(Statement stmt)
Close a statement, ignoring any errors.

Parameters

stmt
The Statement object to be closed.

close(ResultSet) Method

public static void close(ResultSet rs)
Close a result set, ignoring any errors.

Parameters

rs
The ResultSet object to be closed.

close(ResultSet, Statement, Connection) Method

public static void close(ResultSet rs, 
                         Statement stmt, 
                         Connection con)
Close a connection, statement and resultset, ignoring errors.

Parameters

rs
The ResultSet object to be closed.
stmt
The Statement object to be closed.
con
The Connection object to be closed.

commitConnection(Connection) Method

DEPRECATED in favor of Database.commitConnection()

public static void commitConnection(Connection con)
throws SQLException
Commits the java.sql.Connection that you have been using for CLOB operations. A CLOB becomes inactive as soon as a transaction is committed. You must have auto-commit=false on your connection if you need to have a CLOB available across multiple SQL statements.

The delegate may implement this as a no-op method if it is illegal to do a Connection.commit() for the driver (e.g., jDriver for Oracle XA)

If there is no delegate, this method does a Connection.commit()

Parameters

con
the Connection

Exceptions

SQLException
on an error

getClob(ResultSet, int) Method

DEPRECATED in favor of Database and DatabaseFactory

public static String getClob(ResultSet rs, 
                             int index)
throws SQLException
Get the value of a CLOB column as a string.

This method will only return the value of the CLOB in the current row of the ResultSet. This method does not increment the ResultSet cursor. You must use ResultSet.next() to increment the cursor before calling this method. This allows the method to be used to process multi-row ResultSets.

Parameters

rs
the result set.
index
the column index in the result set.

Returns

the column as a string.

Exceptions

SQLException
thrown on an error.

getClobLocator(Connection, String, String, String) Method

DEPRECATED in favor of Database and DatabaseFactory

public static Clob getClobLocator(Connection con, 
                                  String tableName, 
                                  String clobColumnName, 
                                  String whereClause)
throws SQLException
Retrieve the LOB locator for a CLOB. The method creates a PreparedStatement from the specified parameters and gets the LOB locator from the ResultSet.

This method only returns a single CLOB locator. If the WHERE clause results in mutiple rows, only the CLOB from the first row is returned.

If no JdbcHelperDelegate is specified in application-config.xml then this method will return null.

WARNING: if using a delegate to stream data to a CLOB, then you should use Connection.setAutoCommit(false) before calling this method. This will make the CLOB available across multiple SQL statements.

Parameters

con
the database connection
tableName
the name of the database table
clobColumnName
the name of the column holding the CLOB
whereClause
the where clause (without WHERE keyword)

Returns

a CLOB locator, return null if the ResultSet is empty, return null if no JdbcHelperDelegate is specified in application-config.xml

Exceptions

SQLException
on an error

getConnection(DataSource, int, long) Method

DEPRECATED Use DataSource.getConnection(), set retries and waitTime by configuring the Pool

public static Connection getConnection(DataSource src, 
                                       int retries, 
                                       long waitTime)
throws SQLException
Get a connection from a DataSource.

This method no longer honors the retry parameter; it will use the 'Connection Reserve Timeout' parameter set on the JdbcConnectionPool via the WLS console settings.

Parameters

src
the data source.
retries
No longer used - the settings on the pool are now used
waitTime
No longer used - the settings on the pool are now used

Returns

a connection from the data source on success.

Exceptions

SQLException
thrown on an error getting a connection.

getConnection(DataSource, int) Method

DEPRECATED Use DataSource.getConnection(), set retries and waitTime by configuring the Pool

public static Connection getConnection(DataSource src, 
                                       int retries)
throws SQLException
Get a connection from a DataSource.

This method no longer honors the retry parameter; it will use the 'Connection Reserve Timeout' parameter set on the JdbcConnectionPool cia the WLS console settings.

Parameters

src
the data source.
retries
No longer used - the settings on the pool are now used

Returns

a connection from the data source on success.

Exceptions

SQLException
thrown on an error getting a connection.

getEmptyClobInitializer() Method

DEPRECATED in favor of Database and DatabaseFactory

public static String getEmptyClobInitializer()
throws SQLException
Return the database specific keyword that must be used when inserting a row with an empty CLOB. This method uses the JdbcHelperDelegate. If no JdbcHelperDelegate is specified in application-config.xml then this method will return the empty String.

For example, the method returns EMPTY_CLOB() when an Oracle delegate is used.

Returns

keyword required to insert an empty CLOB, return empty String if not supported, return empty String if no JdbcHelperDelegate is specified in application-config.xml

Exceptions

SQLException
on an error

getInstance() Method

public static JdbcHelper getInstance()

resumeTransaction(Transaction) Method

public static void resumeTransaction(Transaction suspendedTransaction)
Resumes the suspended transaction if it is not null.

Parameters

suspendedTransaction
Transaction to resume.

setClob(PreparedStatement, int, String) Method

DEPRECATED in favor of Database.setClob()

public static void setClob(PreparedStatement stmt, 
                           int index, 
                           String str)
throws SQLException
Set the value of a CLOB column with a string.

Parameters

stmt
the prepared statement.
index
the column index.
str
the CLOB string.

Exceptions

SQLException
thrown on an error.

setClob(PreparedStatement, int, Clob, String) Method

DEPRECATED in favor of Database.setClob()

public static boolean setClob(PreparedStatement stmt, 
                              int index, 
                              Clob clob, 
                              String str)
throws SQLException
If there is a delegate, this method uses JdbcHelperDelegate.writeClobData() If this is done, then the PreparedStatement does not need to be used and the return value, executeRequired, is false. The CLOB should be first located with getClobLocator() If there is no delegate, then this method ignores the Clob argument and sets the value of the String into the CLOB placeholder in the PreparedStatement with setClob(PreparedStatement stmt, int index, String str) and returns executeRequired = true.

WARNING: if using a delegate to stream data to a CLOB, then you should have used Connection.setAutoCommit(false) before calling the CLOB locator method that provided the Clob you are using in this method call. This will make the CLOB available across multiple SQL statements.

Parameters

stmt
the prepared statement.
index
the column index.
clob
the CLOB locator (ignored if no delegate).
str
the String to be set in the CLOB (if delegate) or in the PreparedStatement (if no delegate)

Returns

boolean executeRequired. If false then a delegate was used to directly set the CLOB in the database without using the PreparedStatement. If true then no delegate was used, or the delegate set the Clob value on the statement and the PreparedStatement must be executed to update the database.

Exceptions

SQLException
thrown on an error.

Related Topics

JdbcHelperDelegate.writeClobData(PreparedStatement, int, Clob, String)
JdbcHelper.getClobLocator(Connection, String, String, String)
JdbcHelper.setClob(PreparedStatement, int, String)


setJdbcHelperDelegate(String) Method

DEPRECATED in favor of DatabaseFactory

public static void setJdbcHelperDelegate(String className)

showIsolationLevel(Connection) Method

public static String showIsolationLevel(Connection connection)
throws SQLException
Show transaction isolation level of connection

Exceptions

SQLException

startTransaction() Method

public static UserTransaction startTransaction()
throws SQLException
Start a new transaction

Exceptions

SQLException

suspendTransaction() Method

public static Transaction suspendTransaction()
Suspend any current transaction (unless suspendTransaction is false).

Returns

the suspended transaction (or null if none)