| J2EE 1.4 Application Server Developer's Guide |
Chapter 2
Using the JDBC API for Database AccessThis chapter describes how to use the Java Database Connectivity (JDBC) API for database access with the Sun ONE Application Server. This chapter also provides high level JDBC implementation instructions for servlets and EJB components using the J2EE 1.4 Application Server. The J2EE 1.4 Application Server supports the JDBC 3.0 API, which encompasses the JDBC 2.0 Optional Package API.
This chapter contains the following sections:
General Steps for Creating a JDBC ResourceTo prepare a resource that uses JDBC technology (“JDBC resource”) for use in J2EE applications deployed to the J2EE 1.4 Application Server, perform the following tasks:
For information about how to configure a specific JDBC technology-enabled driver (“JDBC driver”), see "Configurations for Specific JDBC Drivers".
Integrating the JDBC Driver
To use features in the JDBC API, you must choose a JDBC driver to work with the J2EE 1.4 Application Server. Then you must set up the driver. This section covers these topics:
Supported Database Drivers
Supported JDBC drivers are those that have been fully tested by Sun. For a list of the JDBC drivers currently supported by the J2EE 1.4 Application Server, see the J2EE 1.4 Application Server Release Notes.
For configurations of supported and other drivers, see "Configurations for Specific JDBC Drivers".
Making the JDBC Driver JAR Files Accessible
To integrate the JDBC driver into a J2EE 1.4 Application Server domain, you can do either of the following:
Using either classloader makes classes accessible to any application or module across the domain.
Creating a Connection Pool
When you create a connection pool that uses JDBC technology (“JDBC connection pool”) in the J2EE 1.4 Application Server, you can define many of the characteristics of your database connections.
You can create a connection pool in one of these ways:
The “Using The Administration Console” section describes each connection pool setting. The “Using The Command Line Interface” section merely lists syntax and default values.
For additional information about connection pools, including connection pool monitoring, see the J2EE 1.4 Application Server Administrator’s Guide.
Using the Administration Console
To create a JDBC connection pool using the Administration Console, perform the following tasks:
- Login to the Administration Console by going to the following URL in your web browser:
http://localhost:4848/asadmin
- Open the JDBC component.
- Click Connection Pools.
- Click the New button.
- Enter the following information:
- Click the Next button.
- Enter the following information:
- Click the Next button.
- You can change the pool settings listed in the following table.
- Click the Next button.
- You can change the general settings listed in the following table. All of these settings are optional.
- Click the Next button.
- Specify values for any properties your JDBC driver requires. If a property you need is not listed, use the Add button to add it. The following table lists some standard and commonly used properties. For information about the specific properties your database requires, see your database vendor’s documentation.
- Click the Next button and review your selections. You can click the Previous button to go back and change settings.
- Click the Finish button.
Using The Command Line Interface
To create a JDBC connection pool using the command line, use the asadmin create-jdbc-connection-pool command. The syntax is as follows, with defaults shown for optional parameters that have them:
asadmin create-jdbc-connection-pool --user admin_user [--password admin_password] [--passwordfile password_file] [--host localhost] [--port 4848] [--secure | -s] [--terse=false] [--echo=false] [--interactive=true] [--target config_name] --datasourceclassname class_name [--restype javax.sql.DataSource] [--steadypoolsize=8] [--maxpoolsize=32] [--maxwait=60000] [--poolresize=2] [--idletimeout=300] [--isolationlevel isolation_level] [--isisolationguaranteed=true] [--isconnectvalidatereq=false] [--validationmethod=auto-commit] [--validationtable table_name] [--failconnection=false] [--description text] [--property (name=value)[:name=value]*] connection_pool_id
For more information about the parameters specific to asadmin create-jdbc-connection-pool, see "Using the Administration Console". For more information about the general asadmin parameters (--user, --password, --passwordfile, --host, --port, and --secure), see the J2EE 1.4 Application Server Administrator’s Guide.
For example:
asadmin create-jdbc-connection-pool --user joeuser --password secret --datasourceclassname oracle.jdbc.pool.OracleDataSource --failconnection=true --isconnectvalidatereq=true --property url=jdbc\\:oracle\\:thin\\:@myhost\\:1521\\:V8i:user=staging_lookup _app:password=staging_lookup_app OraclePoollookup
Note that the colon characters (:) within property values must be escaped with double backslashes (\\) on Solaris platforms as shown, because otherwise they are interpreted as property delimiters. On Windows platforms, colon characters (:) must be escaped with single backslashes (\). For details about using escape characters, see the J2EE 1.4 Application Server Administrator’s Guide.
To delete a JDBC connection pool, use the following command:
asadmin delete-jdbc-connection-pool --user admin_user [--password admin_password] [--passwordfile password_file] [--host localhost] [--port 4848] [--secure | -s] [--terse=false] [--echo=false] [--interactive=true] [--target config_name] [--cascade=false] connection_pool_id
For example:
asadmin delete-jdbc-connection-pool --user joeuser --password secret OraclePoollookup
To list JDBC connection pools, use the following command:
asadmin list-jdbc-connection-pools --user admin_user [--password admin_password] [--passwordfile password_file] [--host localhost] [--port 4848] [--secure | -s] [--terse=false] [--echo=false] [--interactive=true] [config_name]
For example:
asadmin list-jdbc-connection-pools --user joeuser --password secret
Creating a JDBC Resource
A JDBC resource, also called a data source, lets you make connections to a database using getConnection(). Create a JDBC resource in one of these ways:
The “Using The Administration Console” section describes each connection pool setting. The “Using The Command Line Interface” section merely lists syntax and default values.
For general information about JDBC resources, see the J2EE 1.4 Application Server Administrator’s Guide.
Using The Administration Console
To create a JDBC resource using the Administration Console, perform these tasks:
- Login to the Administration Console by going to the following URL in your web browser:
http://localhost:4848/asadmin
- Open the JDBC component.
- Click JDBC Resources.
- Click the New button.
- Enter the following information:
- JNDI Name (required) - Enter the JNDI name that application components must use to access the JDBC resource.
- Pool Name (required) - Select from the list the name (or ID) of the connection pool used by this JDBC resource. For more information, see "Creating a Connection Pool".
- Object Type (optional) - Leave the value at its default, which is user.
- Description (optional) - You can enter a text description of the JDBC resource.
- Status - Check the Enabled box to enable the JDBC resource.
If a JDBC resource is disabled, no application component can connect to it, but its configuration remains in the domain.
- Click the OK button.
Using The Command Line Interface
To create a JDBC resource using the command line, use the asadmin create-jdbc-resource command. The syntax is as follows, with defaults shown for optional parameters that have them:
asadmin create-jdbc-resource --user admin_user [--password admin_password] [--passwordfile password_file] [--host localhost] [--port 4848] [--secure | -s] [--terse=false] [--echo=false] [--interactive=true] [--target config_name] --connectionpoolid connection_pool_id [--enabled=true] [--description text] [--property (name=value)[:name=value]*] jndi_name
For more information about the parameters specific to asadmin create-jdbc-resource, see "Using The Administration Console". For more information about the general asadmin parameters (--user, --password, --passwordfile, --host, --port, and --secure), see the J2EE 1.4 Application Server Administrator’s Guide.
For example:
asadmin create-jdbc-resource --user joeuser --password secret --connectionpoolid OraclePoollookup OracleDSlookup
To delete a JDBC resource, use the following command:
asadmin delete-jdbc-resource --user admin_user [--password admin_password] [--passwordfile password_file] [--host localhost] [--port 4848] [--secure | -s] [--terse=false] [--echo=false] [--interactive=true] [--target config_name] jndi_name
For example:
asadmin delete-jdbc-resource --user joeuser --password secret OracleDSlookup
To list JDBC resources, use the following command:
asadmin list-jdbc-resources --user admin_user [--password admin_password] [--passwordfile password_file] [--host localhost] [--port 4848] [--secure | -s] [--terse=false] [--echo=false] [--interactive=true] [config_name]
For example:
asadmin list-jdbc-resources --user joeuser --password secret
Configurations for Specific JDBC DriversThe following JDBC driver and database combinations are supported for J2EE 1.4 Application Server. The combinations listed here have been tested with the J2EE 1.4 Application Server and are found to be J2EE compatible.
For an up to date list of the JDBC drivers currently supported by the J2EE 1.4 Application Server, see the J2EE 1.4 Application Server Release Notes. Other JDBC drivers have been used with J2EE 1.4 Application Server, but J2EE compliance tests have not been completed with these drivers.
For details about how to integrate a JDBC driver and how to use the Administration Console or the command line interface to implement the configuration, see "General Steps for Creating a JDBC Resource".
Note
An Oracle database user running the capture-schema command needs ANALYZE ANY TABLE privileges if that user does not own the schema. These privileges are granted to the user by the database administrator. For information about capture-schema, see "Using the capture-schema Utility".
Inet ORAXO JDBC Driver for Oracle 9.x
The JAR file for this driver is Oranxo.jar.
Configure the connection pool using the following settings:
Configure the JDBC resource using the following settings:
PointBase Type4 Driver
Configure the connection pool using the following settings:
Configure the JDBC resource using the following settings: