com.ibm.as400.access
Class AS400JDBCConnection

java.lang.Object
  |
  +--com.ibm.as400.access.AS400JDBCConnection

public class AS400JDBCConnection
extends java.lang.Object
implements java.sql.Connection

The AS400JDBCConnection class provides a JDBC connection to a specific DB2 for OS/400 database. Use DriverManager.getConnection() to create new AS400JDBCConnection objects.

There are many optional properties that can be specified when the connection is created. Properties can be specified either as part of the URL or in a java.util.Properties object. See JDBC properties for a complete list of properties supported by the AS400JDBCDriver.

Note that a connection may contain at most 9999 open statements.


Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Method Summary
 void clearWarnings()
          Clears all warnings that have been reported for the connection.
 void close()
          Releases the connection's resources immediately instead of waiting for them to be automatically released.
 void commit()
          Commits all changes made since the previous commit or rollback and releases any database locks currently held by the connection.
 java.sql.Statement createStatement()
          Creates a Statement object for executing SQL statements without parameters.
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency)
          Creates a Statement object for executing SQL statements without parameters.
protected  void finalize()
          Closes the connection if not explicitly closed by the caller.
 boolean getAutoCommit()
          Returns the auto-commit state.
 java.lang.String getCatalog()
          Returns the catalog name.
 java.sql.DatabaseMetaData getMetaData()
          Returns the DatabaseMetaData object that describes the connection's tables, supported SQL grammar, stored procedures, capabilities and more.
 java.lang.String getServerJobIdentifier()
          Returns the job identifier of the host server job corresponding to this connection.
 AS400 getSystem()
          Returns the system object which is managing the connection to the AS/400.
 int getTransactionIsolation()
          Returns the transaction isolation level.
 java.util.Map getTypeMap()
          Returns the type map.
 java.sql.SQLWarning getWarnings()
          Returns the first warning reported for the connection.
 boolean isClosed()
          Indicates if the connection is closed.
 boolean isReadOnly()
          Indicates if the connection is in read-only mode.
 java.lang.String nativeSQL(java.lang.String sql)
          Returns the native form of an SQL statement without executing it.
 java.sql.CallableStatement prepareCall(java.lang.String sql)
          Precompiles an SQL stored procedure call with optional input and output parameters and stores it in a CallableStatement object.
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          Precompiles an SQL stored procedure call with optional input and output parameters and stores it in a CallableStatement object.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
          Precompiles an SQL statement with optional input parameters and stores it in a PreparedStatement object.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          Precompiles an SQL statement with optional input parameters and stores it in a PreparedStatement object.
 void rollback()
          Drops all changes made since the previous commit or rollback and releases any database locks currently held by the connection.
 void setAutoCommit(boolean autoCommit)
          Sets the auto-commit mode.
 void setCatalog(java.lang.String catalog)
          This method is not supported.
 void setReadOnly(boolean readOnly)
          Sets the read-only mode.
 void setTransactionIsolation(int level)
          Sets the transaction isolation level.
 void setTypeMap(java.util.Map typeMap)
          Sets the type map to be used for distinct and structured types.
 java.lang.String toString()
          Returns the connection's catalog name.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Clears all warnings that have been reported for the connection. After this call, getWarnings() returns null until a new warning is reported for the connection.
Specified by:
clearWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException - If an error occurs.

close

public void close()
           throws java.sql.SQLException
Releases the connection's resources immediately instead of waiting for them to be automatically released. This rolls back any active transactions, closes all statements that are running in the context of the connection, and disconnects from the server.
Specified by:
close in interface java.sql.Connection
Throws:
java.sql.SQLException - If an error occurs.

commit

public void commit()
            throws java.sql.SQLException
Commits all changes made since the previous commit or rollback and releases any database locks currently held by the connection. This has no effect when the connection is in auto-commit mode.

This method can not be called when the connection is part of a distributed transaction. See AS400JDBCXAResource for more information.

Specified by:
commit in interface java.sql.Connection
Throws:
java.sql.SQLException - If the connection is not open or an error occurs.

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Creates a Statement object for executing SQL statements without parameters. If the same SQL statement is executed many times, it is more efficient to use prepareStatement().

Result sets created using the statement will be type ResultSet.TYPE_FORWARD_ONLY and concurrency ResultSet.CONCUR_READ_ONLY.

Specified by:
createStatement in interface java.sql.Connection
Returns:
The statement object.
Throws:
java.sql.SQLException - If the connection is not open, the maximum number of statements for this connection has been reached, or an error occurs.

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency)
                                   throws java.sql.SQLException
Creates a Statement object for executing SQL statements without parameters. If the same SQL statement is executed many times, it is more efficient to use prepareStatement().
Specified by:
createStatement in interface java.sql.Connection
Parameters:
resultSetType - The result set type. Valid values are:
  • ResultSet.TYPE_FORWARD_ONLY
  • ResultSet.TYPE_SCROLL_INSENSITIVE
  • ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - The result set concurrency. Valid values are:
  • ResultSet.CONCUR_READ_ONLY
  • ResultSet.CONCUR_UPDATABLE
Returns:
The statement object.
Throws:
java.sql.SQLException - If the connection is not open, the maximum number of statements for this connection has been reached, the result type or currency is not supported, or an error occurs.

finalize

protected void finalize()
                 throws java.lang.Throwable
Closes the connection if not explicitly closed by the caller.
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - If an error occurs.

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Returns the auto-commit state.
Specified by:
getAutoCommit in interface java.sql.Connection
Returns:
true if the connection is in auto-commit mode; false otherwise.
Throws:
java.sql.SQLException - If the connection is not open.

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Returns the catalog name.
Specified by:
getCatalog in interface java.sql.Connection
Returns:
The catalog name.
Throws:
java.sql.SQLException - If the connection is not open.

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Returns the DatabaseMetaData object that describes the connection's tables, supported SQL grammar, stored procedures, capabilities and more.
Specified by:
getMetaData in interface java.sql.Connection
Returns:
The metadata object.
Throws:
java.sql.SQLException - If an error occurs.

getServerJobIdentifier

public java.lang.String getServerJobIdentifier()
Returns the job identifier of the host server job corresponding to this connection. Every JDBC connection is associated with a host server job on the AS/400. The format is:

Note: Since this method is not defined in the JDBC Connection interface, you typically need to cast a Connection object to AS400JDBCConnection in order to call this method:

String serverJobIdentifier = ((AS400JDBCConnection)connection).getServerJobIdentifier();
Returns:
The server job identifier, or null if not known.

getSystem

public AS400 getSystem()
Returns the system object which is managing the connection to the AS/400.

Note: Since this method is not defined in the JDBC Connection interface, you typically need to cast a Connection object to AS400JDBCConnection in order to call this method:

AS400 system = ((AS400JDBCConnection)connection).getSystem();
Returns:
The system.

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Returns the transaction isolation level.
Specified by:
getTransactionIsolation in interface java.sql.Connection
Returns:
The transaction isolation level. Possible values are:
  • TRANSACTION_NONE
  • TRANSACTION_READ_UNCOMMITTED
  • TRANSACTION_READ_COMMITTED
  • TRANSACTION_REPEATABLE_READ
Throws:
java.sql.SQLException - If the connection is not open.

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
Returns the type map.

This driver does not support the type map.

Specified by:
getTypeMap in interface java.sql.Connection
Returns:
The type map.
Throws:
java.sql.SQLException - This exception is always thrown.

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Returns the first warning reported for the connection. Subsequent warnings may be chained to this warning.
Specified by:
getWarnings in interface java.sql.Connection
Returns:
The first warning or null if no warnings have been reported.
Throws:
java.sql.SQLException - If an error occurs.

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Indicates if the connection is closed.
Specified by:
isClosed in interface java.sql.Connection
Returns:
true if the connection is closed; false otherwise.
Throws:
java.sql.SQLException - If an error occurs.

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
Indicates if the connection is in read-only mode.
Specified by:
isReadOnly in interface java.sql.Connection
Returns:
true if the connection is in read-only mode; false otherwise.
Throws:
java.sql.SQLException - If the connection is not open.

nativeSQL

public java.lang.String nativeSQL(java.lang.String sql)
                           throws java.sql.SQLException
Returns the native form of an SQL statement without executing it. The JDBC driver converts all SQL statements from the JDBC SQL grammar into the native DB2 for OS/400 SQL grammar prior to executing them.
Specified by:
nativeSQL in interface java.sql.Connection
Parameters:
sql - The SQL statement in terms of the JDBC SQL grammar.
Returns:
The translated SQL statement in the native DB2 for OS/400 SQL grammar.
Throws:
java.sql.SQLException - If the SQL statement has a syntax error.

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       throws java.sql.SQLException
Precompiles an SQL stored procedure call with optional input and output parameters and stores it in a CallableStatement object. This object can be used to efficiently call the SQL stored procedure multiple times.

Result sets created using the statement will be type ResultSet.TYPE_FORWARD_ONLY and concurrency ResultSet.CONCUR_READ_ONLY.

Specified by:
prepareCall in interface java.sql.Connection
Parameters:
sql - The SQL stored procedure call.
Returns:
The callable statement object.
Throws:
java.sql.SQLException - If the connection is not open, the maximum number of statements for this connection has been reached, or an error occurs.

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       throws java.sql.SQLException
Precompiles an SQL stored procedure call with optional input and output parameters and stores it in a CallableStatement object. This object can be used to efficiently call the SQL stored procedure multiple times.
Specified by:
prepareCall in interface java.sql.Connection
Parameters:
sql - The SQL statement.
resultSetType - The result set type. Valid values are:
  • ResultSet.TYPE_FORWARD_ONLY
  • ResultSet.TYPE_SCROLL_INSENSITIVE
  • ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - The result set concurrency. Valid values are:
  • ResultSet.CONCUR_READ_ONLY
  • ResultSet.CONCUR_UPDATABLE
Returns:
The prepared statement object.
Throws:
java.sql.SQLException - If the connection is not open, the maximum number of statements for this connection has been reached, the result type or currency is not valid, or an error occurs.

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Precompiles an SQL statement with optional input parameters and stores it in a PreparedStatement object. This object can be used to efficiently execute this SQL statement multiple times.

Result sets created using the statement will be type ResultSet.TYPE_FORWARD_ONLY and concurrency ResultSet.CONCUR_READ_ONLY.

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
sql - The SQL statement.
Returns:
The prepared statement object.
Throws:
java.sql.SQLException - If the connection is not open, the maximum number of statements for this connection has been reached, or an error occurs.

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency)
                                            throws java.sql.SQLException
Precompiles an SQL statement with optional input parameters and stores it in a PreparedStatement object. This object can be used to efficiently execute this SQL statement multiple times.
Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
sql - The SQL statement.
resultSetType - The result set type. Valid values are:
  • ResultSet.TYPE_FORWARD_ONLY
  • ResultSet.TYPE_SCROLL_INSENSITIVE
  • ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - The result set concurrency. Valid values are:
  • ResultSet.CONCUR_READ_ONLY
  • ResultSet.CONCUR_UPDATABLE
Returns:
The prepared statement object.
Throws:
java.sql.SQLException - If the connection is not open, the maximum number of statements for this connection has been reached, the result type or currency is not valid, or an error occurs.

rollback

public void rollback()
              throws java.sql.SQLException
Drops all changes made since the previous commit or rollback and releases any database locks currently held by the connection. This has no effect when the connection is in auto-commit mode.

This method can not be called when the connection is part of a distributed transaction. See AS400JDBCXAResource for more information.

Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException - If the connection is not open or an error occurs.

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
Sets the auto-commit mode. If the connection is in auto-commit mode, then all of its SQL statements are executed and committed as individual transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by either a commit or rollback.

By default, the connection is in auto-commit mode. The commit occurs when the statement execution completes or the next statement execute occurs, whichever comes first. In the case of statements returning a result set, the statement execution completes when the last row of the result set has been retrieved or the result set has been closed. In advanced cases, a single statement may return multiple results as well as output parameter values. Here the commit occurs when all results and output parameter values have been retrieved.

The auto-commit mode is always false when the connection is part of a distributed transaction. See AS400JDBCXAResource for more information.

Specified by:
setAutoCommit in interface java.sql.Connection
Parameters:
autoCommit - true to turn on auto-commit mode, false to turn it off.
Throws:
java.sql.SQLException - If the connection is not open or an error occurs.

setCatalog

public void setCatalog(java.lang.String catalog)
                throws java.sql.SQLException
This method is not supported.
Specified by:
setCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException - If the connection is not open.

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws java.sql.SQLException
Sets the read-only mode. This will provide read-only access to the database. Read-only mode can be useful by enabling certain database optimizations. If the caller specified "read only" or "read call" for the "access" property, then the read-only mode cannot be set to false. The read-only mode cannot be changed while in the middle of a transaction.

This method can not be called when the connection is part of a distributed transaction. See AS400JDBCXAResource for more information.

Specified by:
setReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException - If the connection is not open, a transaction is active, or the "access" property is set to "read only".

setTransactionIsolation

public void setTransactionIsolation(int level)
                             throws java.sql.SQLException
Sets the transaction isolation level. The transaction isolation level cannot be changed while in the middle of a transaction.

JDBC and DB2/400 use different terminology for transaction isolation levels. The following table provides a terminology mapping:

AS/400 isolation levelJDBC transaction isolation level
*CHG TRANSACTION_READ_UNCOMMITTED
*CS TRANSACTION_READ_COMMITTED
*ALL TRANSACTION_READ_REPEATABLE_READ
*RR TRANSACTION_SERIALIZABLE

Specified by:
setTransactionIsolation in interface java.sql.Connection
Parameters:
level - The transaction isolation level. Possible values are:
  • TRANSACTION_READ_UNCOMMITTED
  • TRANSACTION_READ_COMMITTED
  • TRANSACTION_REPEATABLE_READ
  • TRANSACTION_SERIALIZABLE
Throws:
java.sql.SQLException - If the connection is not open, the input level is not valid or unsupported, or a transaction is active.

setTypeMap

public void setTypeMap(java.util.Map typeMap)
                throws java.sql.SQLException
Sets the type map to be used for distinct and structured types.

Note: Distinct types are supported by DB2 for OS/400, but are not externalized by the AS/400 Toolbox for Java JDBC driver. In other words, distinct types behave as if they are the underlying type. Structured types are not supported by DB2 for OS/400. Consequently, this driver does not support the type map.

Specified by:
setTypeMap in interface java.sql.Connection
Parameters:
typeMap - The type map.
Throws:
java.sql.SQLException - This exception is always thrown.

toString

public java.lang.String toString()
Returns the connection's catalog name. This is the name of the server.
Overrides:
toString in class java.lang.Object
Returns:
The catalog name.