DataSource Configuration

Frequently an application only needs to access a single database in the course of a transaction. In these circumstances, you can avoid the overhead of a full XA transaction by using a local- or no- transaction configuration.

To provide maximum compatibility with drivers, his type of configuration uses the JDBC Driver type configuation mechanism rather than a DataSource.

Connection Transaction Types

A datasource is configued in a -ds.xml file using a <no-tx-datasource> or <local-tx-datasource> element.

A <no-tx-datasource> does not support transactional behaviour; all operations are atomic in themselves just as if autoCommit was true for the underlying JDBC Connection.

A <local-tx-datasource> supports transactional behaviour by delegating the transaction to the underlying database. However, the duration of the transaction is determined by the Transaction Manager and the commit and rollback methods must not be used by an application.

Connection Properties

The following elements are used to configure the JDBC connection:

<jndi-name> Required
The name with which this DataSource will be bound into JNDI. A value of "MyDS" will be bound to the absolute name "java:/MyDS".
<connection-url> Required
The JDBC connection URL to use when creating a connection. The syntax of the URL is driver specific.
<driver-class> Required
The fully qualified class name for the JDBC driver.
<connection-property> Optional

Additional property values that will be supplied to the JDBC driver when obtaining a connection. For example:

<connection-property name="databaseName">
<user-name> Required*
The username to be used when obtaining a connection. This element is required unless other security is configured.
<password> Required*
The password to be used when obtaining a connection. This element is required unless other security is configured.

An example of a very simple configuration for connecting to an Oracle database would be:


Connection Management

Once a connection has been obtained, the following elements can be used to determine how it is managed by the connector:

<min-pool-size> Default 0
The minimum number of connections that will be retained in the connection pool.
<max-pool-size> Default 20
The maximum number of connections that will be entered in the connection pool.
<blocking-timeout-millis> Default 5000
The amount of time that a thread will wait for a connection to be released if the pool is full. If less than <max-pool-size> connections have been allocated, the thread nevers blocks but instead allocates a new connection.
<idle-timeout-minutes> Default 15

The approximate time that a connection will remain idle before being closed. Idle connections are checked for at an interval of half the lowest value for all connection pools; thus a connection may actually remain in the pool for between 1 and 1.5 times this value.

This value can be used to prevent errors when the underlying driver automatically closes idle connections.

<transaction-isolation> Optional

The isolation level to use for this connection.

This can be specified using the constants defined in java.sql.Connection:


Alternatively an integer value can be used to specify driver-specific levels.

If omitted, this will default to the default isolation level provided by the database and driver.

<new-connection-sql> Optional
An SQL statement that will be executed immediately after a connection is created.
<valid-connection-sql> Optional

An SQL statement that will be executed whenever a connection is obtained from the pool to determine if it is still usable. Any SQLException thrown will cause the connection to be discarded before it is returned to the application.

See Handling Connection Errors for more information.



The fully qualifed name of a class which can be used to detect SQLExceptions that indicate unusable connections. Should such an SQLException be thrown, then the connection will immediately be discarded from the pool.

See Handling Connection Errors for more information.