Sun Java System Application Server 8 2004Q4 Beta Platform Edition Administration Guide |
Chapter 3
JDBC ResourcesThis chapter explains how to configure JDBC resources, which are required by applications that access databases. This chapter contains the following sections:
About JDBC ResourcesJDBC Resources
To store, organize, and retrieve data, most applications use relational databases. J2EE applications access relational databases through the JDBC API.
A JDBC resource (data source) provides applications with a means of connecting to a database. Typically, the administrator creates a JDBC resource for each database accessed by the applications deployed in a domain. (However, more than one JDBC resource can be created for a database.)
To create a JDBC resource, specify a unique JNDI name that identifies the resource. (See the section JNDI Names and Resources.) Expect to find the JNDI name of a JDBC resource in
java:comp/env/jdbc
subcontext. For example, the JNDI name for the resource of a payroll database could bejava:comp/env/jdbc/payrolldb
. Because all resource JNDI names are in thejava:comp/env
subcontext, when specifying the JNDI name of a JDBC resource in the Admin Console, enter onlyjdbc/
name. For example, for a payroll database specifyjdbc/payrolldb
.JDBC Connection Pools
To create a JDBC resource, specify the connection pool with which it is associated. Multiple JDBC resources can specify a single connection pool.
A JDBC connection pool is a group of reusable connections for a particular database. Because creating each new physical connection is time consuming, the server maintains a pool of available connections to increase performance. When an application requests a connection, it obtains one from the pool. When an application closes a connection, the connection is returned to the pool.
The properties of connection pools can vary with different database vendors. Some common properties are the database's name (URL), user name, and password.
How JDBC Resources and Connection Pools Work Together
To store, organize, and retrieve data, most applications use relational databases. J2EE applications access relational databases through the JDBC API. Before an application can access a database, it must get a connection.
At runtime, here's what happens when an application connects to a database:
- The application gets the JDBC resource (data source) associated with the database by making a call through the JNDI API.
Given the resource's JNDI name, the naming and directory service locates the JDBC resource. Each JDBC resource specifies a connection pool.
- Via the JDBC resource, the application gets a database connection.
Behind the scenes, the application server retrieves a physical connection from the connection pool that corresponds to the database. The pool defines connection attributes such as the database name (URL), user name, and password.
- Now that it's connected to the database, the application can read, modify, and add data to the database.
The applications access the database by making calls to the JDBC API. The JDBC driver translates the application's JDBC calls into the protocol of the database server.
- When it's finished accessing the database, the application closes the connection.
The application server returns the connection to the connection pool. Once it's back in the pool, the connection is available for the next application.
Setting Up Database AccessGeneral Steps for Setting Up Database Access
- Install a supported database product. For a list of database products supported by the Application Server, see the link to the Release Notes in the section Further Information.
- Install a JDBC driver for the database product.
- Make the driver's JAR file accessible to the domain's server instance. See Integrating a JDBC Driver.
- Create the database. Usually, the application provider delivers scripts for creating and populating the database.
- Create a connection pool for the database. See Creating a JDBC Connection Pool.
- Create a JDBC resource that points to the connection pool. See Creating a JDBC Resource.
Integrating a JDBC Driver
A JDBC driver translates an application's JDBC calls into the protocol of the database server. To integrate the JDBC driver into an administrative domain, do either of the following:
- Make the driver accessible to the common class loader.
- Make the driver accessible to the system class loader.
- In the Admin Console's tree view, select Configurations.
- Select the desired configuration (for example, default-config).
- Select JVM Settings.
- On the JVM Settings page, click the Path Settings tab.
- In the Classpath Suffix field, enter the fully-qualified path name for the driver's JAR file.
- Click Save.
- Restart the server.
Admin Console Tasks for JDBC Connection PoolsCreating a JDBC Connection Pool
A JDBC connection pool is a group of reusable connections for a particular database. When creating the pool with the Admin Console, the Administratior is actually defining the aspects of a connection to a specific database.
Before creating the pool, you must first install and integrate the JDBC driver.
When building the Create Connection Pool pages, certain data specific to the JDBC driver and the database vendor must be entered. Before proceeding, gather the following information:
To create a JDBC connection pool:
- In the tree component, expand the Resources node.
- Under Resources, expand the JDBC node.
- Under JDBC, select the Connection Pools node.
- On the Connection Pools page, click New.
- On the first Create Connection Pool page, specify the following general settings:
- Click Next.
- On the second Create Connection Pool page, specify the value for the DataSource Class Name field.
If the JDBC driver has a DataSource class for the resource type and database vendor specified in the previous page, then the value of the DataSource Class Name field is provided.
- Click Next.
- On the third and last Create Connection Pool page, perform these tasks:
- In the General Settings section, verify that the values are correct.
- For the fields in the Pool Settings, Connection Validation, and Transaction Isolation sections, retain the default values.
It is most convenient to change these settings at a later time. See Editing a JDBC Connection Pool.
- In the Additional Properties table, add the required properties, such as database name (URL), user name, and password.
- Click Finish.
Equivalent
asadmin
command:create-jdbc-connection-pool
Editing a JDBC Connection Pool
The Edit JDBC Connection Pool page provides the means to change all of the settings for an existing pool, except its name.
To access the Edit JDBC Connection Pool page:
- In the tree component, expand the Resources node.
- Under Resources, expand the JDBC node.
- Under JDBC, expand the Connection Pools node.
- Select the node for the pool you want to edit.
- On the Edit JDBC Connection Pool page, make the necessary changes.
See the following sections for explanations of the settings that might change.
- Click Save.
The Edit JDBC Connection Pool page is divided into these sections:
General Settings
The values of the general settings depend on the specific JDBC driver that is installed. These settings are the names of classes or interfaces in the Java programming language.
Pool Settings
A set of physical database connections reside in the pool. When an application requests a connection, the connection is removed from the pool, and when the application releases the connection, it is returned to the pool.
Connection Validation
Optionally, the application server can validate connections before they are passed to applications. This validation allows the application server to automatically re-establish database connections if the database becomes unavailable due to network failure or database server crash. Validation of connections incurs additional overhead and slightly reduces performance.
Transaction Isolation
Because a database is usually accessed by many users concurrently, one transaction might update data while another attempts to read the same data. The isolation level of a transaction defines the degree to which the data being updated is visible to other transactions. For details on isolation levels, refer to the documentation of the database vendor.
Properties
In the Additional Properties table, it is possible to specify properties, such as the database name (URL), user name, and password. Because the properties vary with database vendor, consult the vendor's documentation for details.
Verifying Connection Pool Settings
To verify the connection pool settings:
Deleting a JDBC Connection Pool
Equivalent
asadmin
command:delete-jdbc-connection-pool
Admin Console Tasks for JDBC ResourcesCreating a JDBC Resource
A JDBC resource (data source) provides applications with a means of connecting to a database. Before creating a JDBC resource, first create a JDBC connection pool.
To create a JDBC resource:
- In the tree component, expand the Resources node.
- Under Resources, expand the JDBC node.
- Under JDBC, select the JDBC Resources node.
- On the JDBC Resources page, click New.
- On the Create JDBC Resource page, specify the resource's settings:
- In the JNDI Name field, type a unique name. By convention, the name begins with the
jdbc/
string. For example:jdbc/payrolldb
. Don't forget the forward slash.- From the Pool Name combo box, choose the connection pool to be associated with the new JDBC resource.
- By default, the resource is available (enabled) as soon as it is created. If you want the resource to be unavailable, deselect the Enabled checkbox.
- In the Description field, type a short description of the resource.
- In the Targets section, specify the targets (clusters and standalone server instances) on which the resource is available. Select the desired target on the left, and click Add to add it to the list of selected targets.
- Click OK.
Equivalent
asadmin
command:create-jdbc-resource
Editing a JDBC Resource
- In the tree component, expand the Resources node.
- Under Resources, expand the JDBC node.
- Under JDBC, expand the JDBC Resources node.
- Select the node for the JDBC resource to be edited.
- On the Edit JDBC Resource page, it is possible to perform these tasks:
- From the Pool Name combo box, select a different connection pool.
- In the Description field, change the short description of the resource.
- Select or deselect the checkbox to enable or disable the resource.
- Select the Targets tab to change the targets (clusters and standalone server instances) on which the resource is available.
Select the checkbox for an existing target in the list, then click Enable to enable the resource for that target or Disable to disable the resource for that target.
Click Manage Targets to add or remove targets to the list. In the Manage Targets page, select the desired target in the Available list on the left, and click Add to add it to the list of selected targets. Click Remove to remove a target from the Selected list.
Click OK to save the changes to the available targets.
- Click Save to apply the edits.
Deleting a JDBC Resource
Equivalent
asadmin
command:delete-jdbc-resource
Admin Console Tasks for Persistence Manager ResourcesCreating a Persistence Manager Resource
This feature is needed for backward compatibility. To run on version 7 of the Application Server, a persistent manager resource was required for applications with container-managed persistence beans (a type of EJB component).
To create a persistence manager resource:
- In the tree component, expand the Resources node.
- Under Resources, select the Persistence Managers node.
- On the Persistence Managers page, click New.
- On the Create Persistence Manager page, specify these settings:
- In the JNDI Name field, type a unique name, for example:
jdo/mypm
. Don't forget the forward slash.- In the Factory Class field, retain the default class provided with this release, or type in the class of another implementation.
- From the Connection Pool combo box, choose the connection pool that the new persistence manager resource will belong to.
- By default, the new persistence manager resource is enabled. To disable it, deselect the Enabled check box.
- In the Targets section, specify the targets (clusters and standalone server instances) on which the resource is available. Select the desired target on the left, and click Add to add it to the list of selected targets.
- Click OK.
Equivalent
asadmin
command:create-persistence-resource
Editing a Persistence Manager Resource
To edit an existing persistence manager resource:
- In the tree component, select the Persistence Managers node.
- Select the node for the persistence manager resource to be edited.
- On the Edit Persistence Manager page, it is possible to perform these tasks:
- From the Connection Pool combo box, select a new connection pool to which the new persistence manager resource belongs.
- Select or deselect the checkbox to enable or disable the resource.
- In the Targets section, specify the targets (clusters and standalone server instances) where the resource resides. Select the desired target on the left, and click Add to add it to the list of selected targets.
- Select the Targets tab to change the targets (clusters and standalone server instances) where the resource resides.
Select the checkbox for an existing target in the list, then click Enable to enable the resource for that target or Disable to disable the resource for that target.
Click Manage Targets to add or remove targets to the list. In the Manage Targets page, select the desired target in the Available list on the left, and click Add to add it to the list of selected targets. Click Remove to remove a target from the Selected list.
Click OK to save the changes to the available targets.
- Click Save.
Deleting a Persistence Manager Resource
Equivalent
asadmin
command:delete-persistence-resource