Sun GlassFish Enterprise Server v3 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 . Use 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

Use the create-jdbc-resource subcommand in remote mode 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. 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 subcommands require a running server.

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

    Information about properties for the subcommand is included in this help page.

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


Example 14–8 Creating a JDBC Resource

This example creates a JDBC resource named DerbyPool.


asadmin> create-jdbc-resource --connectionpoolid DerbyPool jdbc/DerbyPool
Command create-jdbc-resource executed successfully.

See Also

You can also view the full syntax and options of the subcommand by typing asadmin help create-jdbc-resource at the command line.

ProcedureTo List JDBC Resources

Use the list-jdbc-resources subcommand in remote mode to list the existing JDBC resources.

  1. Ensure that the server is running.

    Remote subcommands require a running server.

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


Example 14–9 Listing JDBC Resources

This example lists JDBC resources for localhost.


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

See Also

You can also view the full syntax and options of the subcommand by typing asadmin help list-jdbc-resources at the command line.

ProcedureTo Update a JDBC Resource

You can enable or disable a JDBC resource by using the set subcommand. The JDBC resource is identified by its dotted name.

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

  2. Modify the values for the specified JDBC resource by using the set(1) subcommand.

    For example:


Example 14–10 Updating a JDBC Resource

This example changes the res1 enabled setting to false.


asadmin>set resources.jdbc-resource.res1.enabled=false

ProcedureTo Delete a JDBC Resource

Use the delete-jdbc-resource subcommand in remote mode 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 subcommands require a running server.

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

  3. If necessary, notify users that the JDBC resource is being deleted.

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


Example 14–11 Deleting a JDBC Resource

This example deletes a JDBC resource named DerbyPool.


asadmin> delete-jdbc-resource jdbc/DerbyPool
Command delete-jdbc-resource executed successfully.

See Also

You can also view the full syntax and options of the subcommand by typing asadmin help delete-jdbc-resource at the command line.