# com.bea.p13n.util.jdbc
Database Interface

public interface Database

Provides various BLOB and CLOB handling methods, as well as validity-checking for database drivers. Sub-classed by `GenericDatabase`.

Related Topics

``GenericDatabase``

All Known Implementing Classes
  `GenericDatabase`

## Method Summary

`public boolean` | `accept`(`Connection` connection) Check to see if the Database can bind to the supplied connection.
`public void` | `close`() Close the Connection associated with this Database.
`public void` | `close`(`Reader` reader) Closes a Reader stream.
`public void` | `close`(`InputStream` is) Closes an InputStream.
`public void` | `close`(`Writer` writer) Closes a Writer stream.
`public void` | `close`(`OutputStream` os) Closes an OutputStream.
`public void` | `close`(`Statement` stmt) Closes a Statement.
`public void` | `close`(`PreparedStatement` ps) Closes a PreparedStatement.
`public void` | `close`(`ResultSet` rs) Closes a ResultSet.
`public void` | `close`(`ResultSet` rs, `Statement` stmt) Closes a ResultSet and its associated Statement.
`public boolean` | `commitConnection`(`Connection` connection)
`public void` | `endBlob`() Call Connection.commit().
`public void` | `endClob`() Call Connection.commit().
`public `String`` | `getApplicationName`() Get the name of the current WebLogic J2EE application or return null if not running within a WebLogic J2EE context.
`public byte[]` | `getBlob`(`ResultSet` rs, int index) Get the value of a Blob column as an InputStream.
`public `OutputStream`` | `getBlobLocator`(`Connection` con, `String` tableName, `String` blobColumnName, `String` whereClause)
`public `String`` | `getClob`(`ResultSet` rs, int index) Get the value of a CLOB column as a string.
`public `Clob`` | `getClobLocator`(`Connection` con, `String` tableName, `String` clobColumnName, `String` whereClause)
`public `Connection`` | `getConnection`() Return Connection for the current Database instance.
`public `String`` | `getEmptyBlobInitializer`()
`public `String`` | `getEmptyClobInitializer`()
`public `String`` | `getName`() Gets the name of the database instance.
`public `String`` | `readFromClob`(`Clob` clob) Reads the contents of a Clob and returns as a String.
`public void` | `setClob`(`PreparedStatement` stmt, int index, `String` str) Set the value of a CLOB column with a string.
`public 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 void` | `startBlob`() setAutoCommit( false ) on the Connection.
`public void` | `startClob`() setAutoCommit( false ) on the Connection.
`public void` | `writeToClob`(`Clob` clob, `String` data) Writes the data from a String into a Clob.

## Method Detail

### accept(Connection) Method

    public boolean accept(Connection connection)

Check to see if the Database can bind to the supplied connection.

#### Parameters

connection
  The Connection object that contains the URL.

#### Returns

Returns boolean after checking if this Database can bind to the supplied connection. Typically the Database will examine the Connection MetaData to determine suitability.

### close() Method

    public void close()

Close the Connection associated with this Database.

### close(Reader) Method

    public void close(Reader reader)

Closes a Reader stream.

#### Parameters

reader
  The Reader object to be closed.

### close(InputStream) Method

    public void close(InputStream is)

Closes an InputStream.

#### Parameters

is
  The InputStream object to be closed.

### close(Writer) Method

    public void close(Writer writer)

Closes a Writer stream.

#### Parameters

writer
  The Writer object to be closed.

### close(OutputStream) Method

    public void close(OutputStream os)

Closes an OutputStream.

#### Parameters

os
  The OutputStream object to be closed.

### close(Statement) Method

    public void close(Statement stmt)

Closes a Statement.

#### Parameters

stmt
  The Statement object to be closed.

### close(PreparedStatement) Method

    public void close(PreparedStatement ps)

Closes a PreparedStatement.

#### Parameters

ps
  The PreparedStatement object to be closed.

### close(ResultSet) Method

    public void close(ResultSet rs)

Closes a ResultSet.

#### Parameters

rs
  The ResultSet object to be closed.

### close(ResultSet, Statement) Method

    public void close(ResultSet rs,
                      Statement stmt)

Closes a ResultSet and its associated Statement.

#### Parameters

rs
  The ResultSet object to be closed.

stmt
  The Statement object to be closed.

### commitConnection(Connection) Method

    public boolean commitConnection(Connection connection)
         throws SQLException

#### Exceptions

``SQLException``

### endBlob() Method

    public void endBlob()
         throws SQLException

Call Connection.commit().

#### Exceptions

``SQLException``
  Thrown when error occurs while persisting Blob.

### endClob() Method

    public void endClob()
         throws SQLException

Call Connection.commit().

#### Exceptions

``SQLException``
  Thrown when error occurs while persisting Clob.

### getApplicationName() Method

    public String getApplicationName()

Get the name of the current WebLogic J2EE application or return null if not running within a WebLogic J2EE context.

#### Returns

The name of the current WebLogic J2EE application.

### getBlob(ResultSet, int) Method

    public byte[] getBlob(ResultSet rs,
                        int index)
         throws SQLException

Get the value of a Blob column as an InputStream.

This method will only return the value of the Blob 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 ResultSet.

#### Returns

An InputStream representing the column Blob.

#### Exceptions

``SQLException``
  thrown on an error.

### getBlobLocator(Connection, String, String, String) Method

    public OutputStream getBlobLocator(Connection con,
                                       String tableName,
                                       String blobColumnName,
                                       String whereClause)
         throws SQLException

#### Exceptions

``SQLException``

### getClob(ResultSet, int) Method

    public 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.

If no JdbcHelperDelegate is specified in the console (configured via JdbcHelperMBean) then this method will return a string obtained using the default method that was used before a delegate model was implemented for this class. That method uses Clob.getCharacterStream() to construct a BufferedReader that is read in with the readLine() method.

#### 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

    public Clob getClobLocator(Connection con,
                               String tableName,
                               String clobColumnName,
                               String whereClause)
         throws SQLException

#### Exceptions

``SQLException``

### getConnection() Method

    public Connection getConnection()

Return Connection for the current Database instance.

#### Returns

The Connection of the current Database instance.

### getEmptyBlobInitializer() Method

    public String getEmptyBlobInitializer()
         throws SQLException

#### Exceptions

``SQLException``

### getEmptyClobInitializer() Method

    public String getEmptyClobInitializer()
         throws SQLException

#### Exceptions

``SQLException``

### getName() Method

    public String getName()

Gets the name of the database instance.

#### Returns

The name of the database instance.

### readFromClob(Clob) Method

    public String readFromClob(Clob clob)
         throws SQLException

Reads the contents of a Clob and returns as a String.

#### Exceptions

``SQLException``
  Thrown when error occurs while reading Clob.

### setClob(PreparedStatement, int, String) Method

    public 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

    public 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.

### startBlob() Method

    public void startBlob()
         throws SQLException

setAutoCommit( false ) on the Connection.

#### Exceptions

``SQLException``
  Thrown when trying to set auto-commit to false.

### startClob() Method

    public void startClob()
         throws SQLException

setAutoCommit( false ) on the Connection.

#### Exceptions

``SQLException``
  Thrown when trying to set auto-commit to false.

### writeToClob(Clob, String) Method

    public void writeToClob(Clob clob,
                            String data)
         throws SQLException

Writes the data from a String into a Clob.

#### Exceptions

``SQLException``
  Thrown when error occurs while writing to Clob.