Sun Java™ System Application Server Platform Edition 8 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, you’ll create a JDBC resource for each database accessed by the applications deployed in a domain. (However, you may create more than one JDBC resource for a database.)
When you create a JDBC resource, you specify a unique JNDI name that identifies the resource. (See the section JNDI Names and Resources.) The JNDI name of a JDBC resource should be 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 you specify the JNDI name of a JDBC resource in the Admin Console, you enter onlyjdbc/
name. For example, for a payroll database you would specifyjdbc/payrolldb
.JDBC Connection Pools
When you create a JDBC resource, you specify the connection pool that it is associated with. Multiple JDBC resources may 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 may 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 datase:
- 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 application 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 that needs it.
Setting Up Database AccessGeneral Steps for Setting Up Database Access
- Install a supported database product. For a list of database products supported by the Sun Java System Application Server Platform Edition 8, 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, you can 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 Application Server.
- On the Application Server page, select the JVM Settings tab.
- On the JVM General Settings page, click the Path Settings option.
- On the JVM Classpath Settings page, 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 you create the pool with the Admin Console, you are actually defining the aspects of a connection to a specific database.
Before creating the pool, you must first install and integrate the JDBC driver.
As you step through the Create Connection Pool pages, you’ll enter information that depends on the specific JDBC driver and database vendor. Before proceeding, gather the following information:
To create a JDBC connection pool:
- In the tree component, expand the JDBC node.
- 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 you 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, you may retain the default values.
You can change these settings at a later time. See Editing a JDBC Connection Pool.
- In the Additonal 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 enables you to change all of the settings for an existing pool, except its name.
To access the Edit JDBC Connection Pool page:
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 you’ve 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 will incur additional overhead and slightly reduce 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, you can specify properties such as the database name (URL), user name, and password. Because the properties vary with database vendor, you should consult the vendor’s documentation for details.
Pinging the Database
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, you must first create a JDBC connection pool.
To create a JDBC resource:
- In the tree component, expand the JDBC node.
- Expand the JDBC Resources node.
- On the JDBC Resources page, click New.
- On the Create JDBC Resources page, specify the resource’s settings:
- In the JNDI Name field, type a uniqe name. By convention, the name should begin with the
jdbc/
string. For example:jdbc/payrolldb
. Don’t forget the forward slash.- From the Pool Name combo box, choose the connection pool that the new JDBC resource will belong to.
- 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.
- Click OK.
Equivalent
asadmin
command:create-jdbc-resource
Editing a JDBC Resource
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 compatibilty. To run on version 7 of the Application Server, a persistent manager resource was required for applications with container-managed persistent beans (a type of EJB component).
To create a persistence manager resource:
- In the tree component, 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 uniqe name. gor 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 implmementation.
- From the Connection Pool combo box, choose the connection pool that the new persistence manager resource will belong to.
- By default, the new peristence manager resource will be enabled. To disable it, deselct the Enabled check box.
Equivalent
asadmin
command:create-persistence-resource