Sun GlassFish Enterprise Server v3 Prelude Administration Guide

Administering JDBC Resources

A JDBC resource, also known as a data source, provides an application with a means of connecting to a database. Typically, you create a JDBC resource for each database that is accessed by the applications deployed in a domain. Multiple JDBC resources can be specified for a database.

A JDBC resource is created by specifying the connection pool with which the resource will be associated . Unse a unique Java Naming and Directory Interface (JNDI) name to identify the resource. For example, the JNDI name for the resource of a payroll database might be java:comp/env/jdbc/payrolldb.

The following tasks and information are used to administer JDBC resources:

ProcedureTo Create a JDBC Resource

The remote create-jdbc-resource command enables you to create a JDBC resource. Creating a JDBC resource is a dynamic event and does not require server restart.

Because all JNDI names are in the java:comp/env subcontext, when specifying the JNDI name of a JDBC resource in the Administration Console, use only the jdbc/name format is used. For example, a payroll database might be specified as jdbc/payrolldb.

Before You Begin

Before creating a JDBC resource, you must first create a JDBC connection pool. For instructions, see To Create a JDBC Connection Pool.

  1. Ensure that the server is running.

    Remote commands require a running server.

  2. Create a JDBC resource by using the create-jdbc-resource(1) command.

  3. If necessary, notify users that the new resource has been created.


Example 5–7 Creating a JDBC Resource

The following example command creates a JDBC resource named DerbyPool:


asadmin create-jdbc-resource --connectionpoolid DerbyPool jdbc/DerbyPool

Information similar to the following is displayed if the connection pool is usable:


Command create-jdbc-resource executed successfully.

See Also

To see the full syntax and options of the command, type asadmin create-jdbc-resource --help at the command line.

ProcedureTo List JDBC Resources

The remote list-jdbc-resources command enables you to list the existing JDBC resources.

  1. Ensure that the server is running.

    Remote commands require a running server.

  2. List JDBC resources by using the list-jdbc-resources(1) command.


Example 5–8 Listing JDBC Resources

The following example command lists JDBC resources for localhost:


asadmin list-jdbc-resources

Information similar to the following is displayed:


jdbc/__TimerPool
jdbc/DerbyPool
jdbc/__default
jdbc1
Command list-jdbc-resources executed successfully.

See Also

To see the full syntax and options of the command, type asadmin list-jdbc-resources --help at the command line.

ProcedureTo Delete a JDBC Resource

This remote command enables you to delete an existing JDBC resource. Deleting a JDBC resource is a dynamic event and does not require server restart.

Before You Begin

Before deleting a JDBC resource, all associations with this resource must be removed.

  1. Ensure that the server is running.

    Remote commands require a running server.

  2. Obtain the exact name of the JDBC resource that you are deleting.

    To list the existing JDBC resources:


    asadmin list-jdbc-resources
    
  3. If necessary, notify users that the JDBC resource is being deleted.

  4. Delete a JDBC resource by using the delete-jdbc-resource(1) command.


Example 5–9 Deleting a JDBC Resource

The following example command deletes a JDBC resource named DerbyPool:


asadmin delete-jdbc-resource jdbc/DerbyPool

Information similar to the following is displayed:


Command delete-jdbc-resource executed successfully.

See Also

To see the full syntax and options of the command, type asadmin delete-jdbc-resource --help at the command line.