com.ibm.db
Class DatabaseConnection

java.lang.Object
  |
  +--com.ibm.db.DatabaseConnection

public class DatabaseConnection
extends java.lang.Object
implements java.io.Serializable

DatabaseConnection represents a connection to the database.

See Also:
Statement, Serialized Form

Field Summary
protected  DatabaseConnectionAfterListener aDatabaseConnectionAfterListener
           
protected  DatabaseConnectionBeforeListener aDatabaseConnectionBeforeListener
           
protected  DatabaseConnection connection
           
private static java.lang.String copyright
           
protected  java.lang.String databaseName
           
private  boolean externallyManaged
           
protected  boolean fieldAutoCommit
           
protected  DatabaseConnectionSpec fieldConnectionSpec
           
protected  boolean fieldPromptUID
           
protected  int fieldTransactionIsolation
           
static int POOL_TYPE_NONE
          Do not use connection pools
static int POOL_TYPE_WEBSPHERE
          Use WebSphere connection pools
protected  java.beans.PropertyChangeSupport propertyChange
           
(package private) static long serialVersionUID
           
protected  boolean supportsMixedCaseIdentifiers
           
protected  boolean supportsMixedCaseQuotedIdentifiers
           
protected  boolean supportsPositionedDelete
           
protected  boolean supportsPositionedUpdate
           
static int TRANSACTION_DEFAULT
          Use default transaction isolation level for database.
 
Constructor Summary
  DatabaseConnection()
          Constructs a new DatabaseConnection.
  DatabaseConnection(java.sql.Connection jdbcConnection)
          Constructs a new DatabaseConnection with the specified JDBC connection.
protected DatabaseConnection(DatabaseConnectionSpec connectionSpec)
          Constructs a new DatabaseConnection with the specified DatabaseConnectionSpec.
 
Method Summary
 void addDatabaseConnectionAfterListener(DatabaseConnectionAfterListener listener)
          Adds a listener to the DatabaseConnectionAfter event set.
 void addDatabaseConnectionBeforeListener(DatabaseConnectionBeforeListener listener)
          Adds a listener to the DatabaseConnectionBefore event set.
 void commit()
          Commits changes to the database.
 boolean connect()
          Attempts to establish a connection to the database.
 void disconnect()
          Closes the JDBC connection for further use by this DatabaseConnection object.
protected  void fireAboutToCommit(DataEvent event)
          Method to support listener events.
protected  void fireAboutToConnect(DataEvent event)
          Method to support listener events.
protected  void fireAboutToDisconnect(DataEvent event)
          Method to support listener events.
protected  void fireAboutToRollback(DataEvent event)
          Method to support listener events.
protected  void fireCommitted(DataEvent event)
          Method to support listener events.
protected  void fireConnected(DataEvent event)
          Method to support listener events.
protected  void fireDisconnected(DataEvent event)
          Method to support listener events.
protected  void fireRolledBack(DataEvent event)
          Method to support listener events.
 boolean getAutoCommit()
          Returns true if changes to the database are automatically committed as soon as they are made.
protected  DatabaseConnection getConnection()
          Returns the underlying com.ibm.db.base.DatabaseConnection associated with this DatabaseConnection.
 java.lang.String getConnectionAlias()
          Returns the alias name that is associated with this DatabaseConnection.
 int getConnectionPoolType()
          Deprecated. Use setJndiDataSource() to use a WebSphere datasource to make a connection.
 DatabaseConnectionSpec getConnectionSpec()
          Returns the DatabaseConnectionSpec associated with this DatabaseConnection.
 java.lang.String getDataSourceName()
          Returns the URL used when establishing a connection to the database.
 java.lang.String getDriverName()
          Returns the JDBC driver used when establishing a connection to the database.
 java.lang.String getInitialContextFactory()
          Returns the InitialContextFactory used to locate the JDBC 2.0 DataSource.
 java.sql.DatabaseMetaData getJDBCMetaData()
          Returns the java.sql.DatabaseMetaData associated with this DatabaseConnection.
 java.lang.String getJndiDataSource()
          Returns the name of the JDBC 2.0 DataSource used to obtain a connection to the database.
private  java.lang.String getPassword()
          Returns the password used when establishing a connection to the database.
 boolean getPromptUID()
          Returns true if before a database connection is made, a logon dialog will be displayed to obtain the userid and password for the connection.
 java.util.Properties getProperties()
          Returns the properties for this DatabaseConnection.
 java.lang.String getProviderURL()
          Returns the Provider URL for the InitialContextFactory.
 int getTransactionIsolation()
          Returns the current setting for the transacation isolation level for this DatabaseConnection.
 java.lang.String getUserID()
          Returns the userid used when establishing a connection to the database.
protected static void handleSQLException(java.sql.SQLException ex)
          This method was created by a SmartGuide.
private  void initialize()
          Initiazes the class.
 boolean isConnected()
          Returns true if the DatabaseConnection is associated with an active JDBC connection.
 boolean isExternallyManaged()
          Returns true if the associated JDBC connection is considered to be externally managed.
protected  void obtainConnectionMetaDataInfo()
          This method was created in VisualAge.
private  void readObject(java.io.ObjectInputStream in)
          This method was reads in the serialized object and restores the following static/transient fields: propertyChange - contains a reference to a PropertyChangeSupport instance.
 void removeDatabaseConnectionAfterListener(DatabaseConnectionAfterListener listener)
          Removes a listener from the DatabaseConnectionAfter event set.
 void removeDatabaseConnectionBeforeListener(DatabaseConnectionBeforeListener listener)
          Removes a listener from the DatabaseConnectionBefore event set.
 void rollback()
          Rollback changes in the database.
 void setAutoCommit(boolean autoCommit)
          If true, any changes to the database are automatically committed as soon as they are made.
 void setConnectionAlias(java.lang.String alias)
          Sets the connection alias name used when a connect is invoked on this DatabaseConnection.
 void setConnectionPoolType(int aConnectionPoolType)
          Deprecated. Use setJndiDataSource() to use a WebSphere datasource to make a connection.
protected  void setConnectionSpec(DatabaseConnectionSpec connectionSpec)
          Associates a DatabaseConnectionSpec with this DatabaseConnection.
 void setDataSourceName(java.lang.String dataSourceName)
          Sets the URL used when establishing a connection to the database.
 void setDriverName(java.lang.String driverName)
          Sets the JDBC driver used when establishing a connection to the database.
 void setInitialContextFactory(java.lang.String initialContextFactory)
          Sets the InitialContextFactory used to find the DataSource specified in the JndiDataSource property.
 void setJndiDataSource(java.lang.String dataSource)
          Sets the JNDI DataSource used when establishing a connection to the database.
 void setPassword(java.lang.String password)
          Sets the password used when establishing a connection to the database.
 void setPassword(java.lang.String password, boolean decode)
          Decodes the specified password if requested, and sets the password used when establishing a connection to the database.
 void setPromptUID(boolean promptUID)
          If true, before a database connection is made, a logon dialog will be displayed to obtain the userid and password for the connection.
 void setProperties(java.util.Properties properties)
          Sets the properties to use when establishing a connection.
 void setProviderURL(java.lang.String providerURL)
          Sets the Provider URL for the InitialContext factory.
 void setTransactionIsolation(int isolation)
          Sets the transaction isolation level for the connection.
 void setUserID(java.lang.String userid)
          Sets the userid used when establishing a connection to the database.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

fieldConnectionSpec

protected DatabaseConnectionSpec fieldConnectionSpec

fieldAutoCommit

protected boolean fieldAutoCommit

fieldPromptUID

protected boolean fieldPromptUID

fieldTransactionIsolation

protected int fieldTransactionIsolation

connection

protected transient DatabaseConnection connection

propertyChange

protected transient java.beans.PropertyChangeSupport propertyChange

aDatabaseConnectionBeforeListener

protected transient DatabaseConnectionBeforeListener aDatabaseConnectionBeforeListener

aDatabaseConnectionAfterListener

protected transient DatabaseConnectionAfterListener aDatabaseConnectionAfterListener

externallyManaged

private boolean externallyManaged

databaseName

protected transient java.lang.String databaseName

supportsPositionedUpdate

protected transient boolean supportsPositionedUpdate

supportsPositionedDelete

protected transient boolean supportsPositionedDelete

supportsMixedCaseIdentifiers

protected transient boolean supportsMixedCaseIdentifiers

supportsMixedCaseQuotedIdentifiers

protected transient boolean supportsMixedCaseQuotedIdentifiers

POOL_TYPE_NONE

public static final int POOL_TYPE_NONE
Do not use connection pools

POOL_TYPE_WEBSPHERE

public static final int POOL_TYPE_WEBSPHERE
Use WebSphere connection pools

TRANSACTION_DEFAULT

public static final int TRANSACTION_DEFAULT
Use default transaction isolation level for database.

serialVersionUID

static final long serialVersionUID

copyright

private static final java.lang.String copyright
Constructor Detail

DatabaseConnection

public DatabaseConnection()
Constructs a new DatabaseConnection.

DatabaseConnection

protected DatabaseConnection(DatabaseConnectionSpec connectionSpec)
Constructs a new DatabaseConnection with the specified DatabaseConnectionSpec. Use this constructor when you want to associate a new DatabaseConnection with an existing DatabaseConnectionSpec. A connectionSpec contains the information needed to establish a connection with the database.
Parameters:
connectionSpec - the connectionSpec for the connection
See Also:
DatabaseConnectionSpec

DatabaseConnection

public DatabaseConnection(java.sql.Connection jdbcConnection)
                   throws DataException
Constructs a new DatabaseConnection with the specified JDBC connection. Use this constructor when you already have an open java.sql.Connection that you want to use in a new DatabaseConnection. When you use this constructor, the connection is considered to be externally managed. You cannot issue the connect method against an externally managed DatabaseConnection. When you issue the disconnect method against an externally managed DatabaseConnection, the JDBC connection remains open, but is closed for use by this DatabaseConnection object.
Parameters:
jdbcConnection - open java.sql.Connection
Throws:
DataException - connectionClosed - if the jdbcConnection is closed
DataException - sqlException - if an SQL exception occurred
See Also:
isExternallyManaged()
Method Detail

addDatabaseConnectionAfterListener

public void addDatabaseConnectionAfterListener(DatabaseConnectionAfterListener listener)
Adds a listener to the DatabaseConnectionAfter event set. DatabaseConnectionAfter events occur after connection-scoped actions have completed, such as connect, disconnect, commit, or rollback.
Parameters:
listener - DatabaseConnectionAfterListener
See Also:
DatabaseConnectionAfterListener, removeDatabaseConnectionAfterListener(com.ibm.db.DatabaseConnectionAfterListener)

addDatabaseConnectionBeforeListener

public void addDatabaseConnectionBeforeListener(DatabaseConnectionBeforeListener listener)
Adds a listener to the DatabaseConnectionBefore event set. DatabaseConnectionBefore events occur before connection-scoped actions are performed, such as connect, disconnect, commit, or rollback.
Parameters:
listener - DatabaseConnectionBeforeListener
See Also:
DatabaseConnectionBeforeListener, removeDatabaseConnectionBeforeListener(com.ibm.db.DatabaseConnectionBeforeListener)

commit

public void commit()
            throws DataException
Commits changes to the database. All outstanding changes made to the database using this connection are committed to the database and any database locks currently held by the connection are released. This method should only be used when auto commit has been turned off.

The events aboutToCommit and committed are triggered by this method.

Throws:
DataException - noActiveConnection - if no active connection exists
DataException - sqlException - if an SQL exception occurs
See Also:
setAutoCommit(boolean), rollback()

connect

public boolean connect()
                throws DataException
Attempts to establish a connection to the database.

If a connection already exists for the specified connectionAlias, no new connection is made and the existing connection is shared. If the value of connectionAlias is null, a new connection is always established.

If a JndiDataSource was specified, the DataSource object is obtained from the specified name server and used to obtain a connection. Otherwise, the connection is obtained from the JDBC DriverManager using the URL that was specified in the DataSourceName property. The JDBC driver specified by DriverName is registered prior to attempting to make the connection.

If a URL and DriverName are specified and the connectionPoolType property is POOL_TYPE_WEBSPHERE, the connection is obtained from the WebSphere 2.0 style connection pools. If no connection pool currently exists, a new connection pool with default settings is created based on the specified URL. Then the connection is obtained from the new pool. NOTE: This is a deprecated interface. To use WebSphere 3.0 style connection pools, you should specifiy the WebSphere DataSource name in the JndiDataSource property.

If the connectionPoolType property is POOL_TYPE_NONE, a new connection is obtained directly from the JDBC DriverManager.

The events aboutToConnect and connected are triggered by this method.

Returns:
true if the connection was successfully establish, else false.
Throws:
DataException - externallyManaged - if connection is externally managed
DataException - alreadyConnected - if connection is already established
DataException - noGui - if no GUI available and logon prompt requested
DataException - badUidPwd - if incorrect Userid or password specified
DataException - noTransactions - if database does not support transactions and autoCommit set to false
DataException - sqlException - if an SQLException occurred
DataException - websphereConnectionError - if an error occurred obtaining the connection from WebSphere
See Also:
disconnect(), setConnectionPoolType(int)

disconnect

public void disconnect()
                throws DataException
Closes the JDBC connection for further use by this DatabaseConnection object. A disconnect may or may not be performed on the JDBC connection itself depending on whether the JDBC connection was obtained from a WebSphere 2.0 connection pool, whether it is externally managed, and if neither of the former applies, whether it is being shared by another DatabaseConnection object using the same connection alias.

If the connection is externally managed or is being shared by another DatabaseConnection object, the association between the JDBC connection and the DatabaseConnection object is removed, but the JDBC connection itself is not closed.

If the connection was obtained from a Webshpere 2.0 connection pool and is not externally managed, the JDBC connection is simply released back to the connection pool.

If the connection is not externally managed, is not from a Webshpere 2.0 connection pool, and is not being shared with another DatabaseConnection object, the JDBC connection is closed, releasing the JDBC resources associated with the connection.

If a connection was obtained from a DataSource, closing the connection may simply return the connection to a connection pool, if connection pooling is implemented by the DataSource.

The events aboutToDisconnect and disconnected are triggered by this method.

Throws:
DataException - noActiveConnection - if no active Connection
DataException - notRegistered - if connection alias not registered as in use
DataException - sqlException - if an SQLException occurred
DataException - websphereConnectionError - if an error occurred releasing the connection to WebSphere
See Also:
connect(), setConnectionPoolType(int)

fireAboutToCommit

protected void fireAboutToCommit(DataEvent event)
Method to support listener events.
Parameters:
event - DataEvent

fireAboutToConnect

protected void fireAboutToConnect(DataEvent event)
Method to support listener events.
Parameters:
event - DataEvent

fireAboutToDisconnect

protected void fireAboutToDisconnect(DataEvent event)
Method to support listener events.
Parameters:
event - DataEvent

fireAboutToRollback

protected void fireAboutToRollback(DataEvent event)
Method to support listener events.
Parameters:
event - DataEvent

fireCommitted

protected void fireCommitted(DataEvent event)
Method to support listener events.
Parameters:
event - DataEvent

fireConnected

protected void fireConnected(DataEvent event)
Method to support listener events.
Parameters:
event - DataEvent

fireDisconnected

protected void fireDisconnected(DataEvent event)
Method to support listener events.
Parameters:
event - DataEvent

fireRolledBack

protected void fireRolledBack(DataEvent event)
Method to support listener events.
Parameters:
event - DataEvent

getAutoCommit

public boolean getAutoCommit()
Returns true if changes to the database are automatically committed as soon as they are made.
Returns:
true if the changes are automatically committed, else false.
See Also:
setAutoCommit(boolean)

getConnection

protected DatabaseConnection getConnection()
Returns the underlying com.ibm.db.base.DatabaseConnection associated with this DatabaseConnection. All communication with JDBC is delegated to this underlying object.
Returns:
the underlying ibm.com.db.base.DatabaseConnection
See Also:
#setConnection

getConnectionAlias

public java.lang.String getConnectionAlias()
Returns the alias name that is associated with this DatabaseConnection.
Returns:
the alias name
See Also:
setConnectionAlias(java.lang.String)

getConnectionPoolType

public int getConnectionPoolType()
Deprecated. Use setJndiDataSource() to use a WebSphere datasource to make a connection.

Returns the connection pool type. This interface is deprecated. You should set the DataSource name to use the WAS connection pools.
Returns:
the connection pool type - POOL_TYPE_NONE indicates no connections pools are used. POOL_TYPE_WEBSPHERE indicates WebSphere connection pools are used.
See Also:
setConnectionPoolType(int), setJndiDataSource(java.lang.String)

getConnectionSpec

public DatabaseConnectionSpec getConnectionSpec()
Returns the DatabaseConnectionSpec associated with this DatabaseConnection. The connectionSpec contains all of the information needed to establish a connection with the database.
Returns:
the associated DatabaseConnectionSpec
See Also:
DatabaseConnectionSpec

getDataSourceName

public java.lang.String getDataSourceName()
Returns the URL used when establishing a connection to the database.
Returns:
the URL for the connection
See Also:
setDataSourceName(java.lang.String)

getDriverName

public java.lang.String getDriverName()
Returns the JDBC driver used when establishing a connection to the database.
Returns:
the JDBC driver name for the connection
See Also:
setDriverName(java.lang.String)

getInitialContextFactory

public java.lang.String getInitialContextFactory()
Returns the InitialContextFactory used to locate the JDBC 2.0 DataSource.
Returns:
the InitialContexFactory used to locate the JDBC 2.0 DataSource.
See Also:
setInitialContextFactory(java.lang.String)

getJDBCMetaData

public java.sql.DatabaseMetaData getJDBCMetaData()
                                          throws DataException
Returns the java.sql.DatabaseMetaData associated with this DatabaseConnection. Returns null if there is no active connection.
Returns:
the associated DatabaseMetaData if there is an active connection; otherwise returns null.
Throws:
DataException - sqlException - if an SQL exception occurs

getJndiDataSource

public java.lang.String getJndiDataSource()
Returns the name of the JDBC 2.0 DataSource used to obtain a connection to the database.
Returns:
the name of the JDBC 2.0 DataSource used to obtain a connection.
See Also:
setJndiDataSource(java.lang.String)

getPassword

private java.lang.String getPassword()
Returns the password used when establishing a connection to the database.
Returns:
the password for the connection
See Also:
setPassword(java.lang.String)

getPromptUID

public boolean getPromptUID()
Returns true if before a database connection is made, a logon dialog will be displayed to obtain the userid and password for the connection.
Returns:
true if logon dialog will be displayed, else false
See Also:
setPromptUID(boolean)

getProperties

public java.util.Properties getProperties()
Returns the properties for this DatabaseConnection. Properties specify keyword/value pairs other than userid and password required for connecting to the database. Userid and password can be set separately.
Returns:
the properties for the connection.
See Also:
setProperties(java.util.Properties), setUserID(java.lang.String), setPassword(java.lang.String)

getProviderURL

public java.lang.String getProviderURL()
Returns the Provider URL for the InitialContextFactory.
Returns:
the provider URL for the InitialContextFactory.
See Also:
setProviderURL(java.lang.String)

getTransactionIsolation

public int getTransactionIsolation()
Returns the current setting for the transacation isolation level for this DatabaseConnection.
Returns:
the current java.sql.Connection.TRANSACTION_* mode value
See Also:
setTransactionIsolation(int)

getUserID

public java.lang.String getUserID()
Returns the userid used when establishing a connection to the database.
Returns:
the userid for the connection
See Also:
setUserID(java.lang.String)

handleSQLException

protected static void handleSQLException(java.sql.SQLException ex)
                                  throws DataException
This method was created by a SmartGuide.
Throws:
DataException - The exception description.

initialize

private void initialize()
Initiazes the class. Creates a DatabaseConnectionSpec object and a DatabaseLogonSpec object if none are already associated with this object.

isConnected

public boolean isConnected()
                    throws DataException
Returns true if the DatabaseConnection is associated with an active JDBC connection. Otherwise returns false.
Returns:
true if associated with an active JDBC connection, else false.
Throws:
DataException - sqlException - if an SQL exception occurs

isExternallyManaged

public boolean isExternallyManaged()
Returns true if the associated JDBC connection is considered to be externally managed. A connect is not allowed for an externally managed connection. When you issue the disconnect method for an externally managed connection, the JDBC connection remains open, but is closed for use by this DatabaseConnection object.
Returns:
true if the connection is externally managed, else false.

obtainConnectionMetaDataInfo

protected void obtainConnectionMetaDataInfo()
                                     throws DataException
This method was created in VisualAge.

readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
This method was reads in the serialized object and restores the following static/transient fields: propertyChange - contains a reference to a PropertyChangeSupport instance.
Parameters:
in - ObjectInputStream

removeDatabaseConnectionAfterListener

public void removeDatabaseConnectionAfterListener(DatabaseConnectionAfterListener listener)
Removes a listener from the DatabaseConnectionAfter event set. DatabaseConnectionAfter events occur after connection-scoped actions have completed, such as connect, disconnect, commit, or rollback.
Parameters:
listener - DatabaseConnectionAfterListener
See Also:
DatabaseConnectionAfterListener, addDatabaseConnectionAfterListener(com.ibm.db.DatabaseConnectionAfterListener)

removeDatabaseConnectionBeforeListener

public void removeDatabaseConnectionBeforeListener(DatabaseConnectionBeforeListener listener)
Removes a listener from the DatabaseConnectionBefore event set. DatabaseConnectionBefore events occur before connection-scoped actions are performed, such as connect, disconnect, commit, or rollback.
Parameters:
listener - DatabaseConnectionBeforeListener
See Also:
DatabaseConnectionBeforeListener, addDatabaseConnectionBeforeListener(com.ibm.db.DatabaseConnectionBeforeListener)

rollback

public void rollback()
              throws DataException
Rollback changes in the database. All changes made since the previous commit/rollback are rolled back and any database locks currently held by the connection are released. This method should only be used when auto commit has been turned off.

The events aboutToRollback and rolledBack are triggered by this method.

Throws:
DataException - noActiveConnection - if no active connection exists
DataException - sqlException - if an SQL exception occurs
See Also:
commit(), setAutoCommit(boolean)

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws DataException
If true, any changes to the database are automatically committed as soon as they are made. Otherwise changes are not committed until commit is issued.

The default value of this property is true.

Parameters:
autoCommit - true - automatically commit changes; false - don't automatically commit changes
Throws:
DataException - sqlException - if an SQL exception occurs
DataException - noTransactions - if database does not support transactions and autoCommit set to false
See Also:
getAutoCommit()

setConnectionAlias

public void setConnectionAlias(java.lang.String alias)
Sets the connection alias name used when a connect is invoked on this DatabaseConnection. If a connection to the database has already been established for this alias name, no new connection is made and the existing connection is shared.
Parameters:
alias - the alias name for the connection
See Also:
getConnectionAlias()

setConnectionPoolType

public void setConnectionPoolType(int aConnectionPoolType)
                           throws DataException
Deprecated. Use setJndiDataSource() to use a WebSphere datasource to make a connection.

Sets the connection pool type for this DatabaseConnection. If the connectionPoolType property is POOL_TYPE_WEBSPHERE and you have not specified a JndiDataSourceName , when you invoke the connect method the connection is obtained from the WebSphere 2.0 connection pools. If no connection pool currently exists, a new connection pool with default settings is created based on the specified URL, and the connection is obtained from the new pool.

If the connectionPoolType property is POOL_TYPE_NONE, a new connection is obtained directly from the JDBC DriverManager or from a DataSource.

This interface is deprecated. You should use setJndiDataSource() to use DataSources to make a database connection.

Parameters:
aConnectionPoolType - POOL_TYPE_NONE indicates WebSphere 2.0 connection pools are not used. POOL_TYPE_WEBSPHERE indicates WebSphere 2.0 connection pools are used, if no JndiDataSourceName was specified.
Throws:
DataException - invalidConnPoolType - if an invalid connection pool type was specified
See Also:
getConnectionPoolType(), setJndiDataSource(java.lang.String)

setConnectionSpec

protected void setConnectionSpec(DatabaseConnectionSpec connectionSpec)
Associates a DatabaseConnectionSpec with this DatabaseConnection.
Parameters:
connectionSpec - the associated DatabaseConnectionSpec
See Also:
getConnectionSpec()

setDataSourceName

public void setDataSourceName(java.lang.String dataSourceName)
Sets the URL used when establishing a connection to the database. A URL specification has the format jdbc:subprotocol:subname, where subprotocol and subname identify the data source for the connection. The value of subprotocol depends on the JDBC driver used. For example, for the DB2 application JDBC driver, subprotocol is db2; for the Oracle thin driver, subprotocol is thin. The value of subname depends on the subprotocol specification; the subname value provides information to locate the database. For example, a full URL specification for an application accessing a local database named sample through the DB2 application JDBC driver is: jdbc:db2:sample. By comparison, a full URL specification for an applet using the Sybase jConnect driver to access a database named sample, on a remote server named myserv, through port number 88 on the internet is: jdbc:sybase:Tds:myserver:88/sample. Here, the subname value includes the database server name, port number, and database name.

This property is only used if the JndiDataSource property is null. If the JndiDataSource property is not null, then this field is ignored and the connection is obtained using the DataSource specified in the JndiDataSource property.

Parameters:
dataSourceName - The URL for the connection.
See Also:
getDataSourceName()

setDriverName

public void setDriverName(java.lang.String driverName)
Sets the JDBC driver used when establishing a connection to the database. This is the class name of the JDBC driver (including the package name). For example, the DB2 application JDBC driver is COM.ibm.db2.jdbc.appDB2Driver.

This property is only used if the JndiDataSource property is null. If the JndiDataSource property is not null, then this field is ignored and the connection is obtained using the DataSource specified in the JndiDataSource property.

Parameters:
driverName - the JDBC driver name for the connection
See Also:
getDriverName()

setInitialContextFactory

public void setInitialContextFactory(java.lang.String initialContextFactory)
Sets the InitialContextFactory used to find the DataSource specified in the JndiDataSource property.
Parameters:
initialContextFactory - The InitialContextFactory to used find the DataSource.
See Also:
getInitialContextFactory()

setJndiDataSource

public void setJndiDataSource(java.lang.String dataSource)
Sets the JNDI DataSource used when establishing a connection to the database. If this field is null, then the connection will be obtained from the DriverManager using the values specified in the DataSourceName and DriverName properties. The values in InitialContextFactory and ProviderURL properties are used to locate the DataSource.
Parameters:
dataSource - The JNDI DataSource to used to obtain the connection
See Also:
getJndiDataSource()

setPassword

public void setPassword(java.lang.String password)
Sets the password used when establishing a connection to the database.
Parameters:
password - the password for the connection
See Also:
setPromptUID(boolean)

setPassword

public void setPassword(java.lang.String password,
                        boolean decode)
                 throws DataException
Decodes the specified password if requested, and sets the password used when establishing a connection to the database.

This method is provided for use by VisualAge for Java in its generated code. Because the encoding/decoding algorithm is proprietary, you should use the method with signature setPassword(String) in code that you write yourself.

Parameters:
password - the password for the connection
decode - true - decode password; false - password is not encoded.
Throws:
DataException - decodeError - if error encountered while decoding password
See Also:
setPromptUID(boolean)

setPromptUID

public void setPromptUID(boolean promptUID)
If true, before a database connection is made, a logon dialog will be displayed to obtain the userid and password for the connection. The userid and password entered in the dialog will override any userid or password that had been previously specified.

The default value of this property is false.

Parameters:
promptUID - true -display logon dialog; false - don't display logon dialog
See Also:
getPromptUID()

setProperties

public void setProperties(java.util.Properties properties)
Sets the properties to use when establishing a connection. Use properties to specify keyword/value pairs other than userid and password required for connecting to the database. Userid and password can be set separately.
Parameters:
properties - the properties for the connection
See Also:
getProperties(), setPassword(java.lang.String), setUserID(java.lang.String)

setProviderURL

public void setProviderURL(java.lang.String providerURL)
Sets the Provider URL for the InitialContext factory.
Parameters:
providerURL - The provider URL for the InitialContextFactory.
See Also:
getProviderURL()

setTransactionIsolation

public void setTransactionIsolation(int isolation)
                             throws DataException
Sets the transaction isolation level for the connection. If the specifiec value is com.ibm.db.DatabaseConnection.TRANSACTION_DEFAULT, no action is taken. The transaction isolation level is left as its default value. Otherwise sets the current transaction isolation level for the connection to the specified level.

Parameters:
isolation - the transaction isolation level
Throws:
DataException - sqlException - if an SQL exception occurs
DataException - noTransactions - if database does not support transactions and transactionIsolation set to something other than TRANSACTION_DEFAULT.
See Also:
getTransactionIsolation()

setUserID

public void setUserID(java.lang.String userid)
Sets the userid used when establishing a connection to the database.
Parameters:
userid - the userid for the connection
See Also:
getUserID(), setPromptUID(boolean)