Setting up a JDBC Resource on the GlassFish Application Server

See Also

A JDBC resource (data source) provides applications with a means of connecting to a database through a connection pool. Typically, there is at least one JDBC resource for each database accessed by an application deployed in a domain. It is possible to have more than one JDBC resource for a database.

When you generate CMP entity beans from a database or use the Enterprise Resources > Use Database command to generate lookup code for a database, the JDBC data sources are generated automatically.

To create a JDBC resource:

  1. Ensure the GlassFish application server is running.
  2. Go to File > New (Ctrl-N).
  3. In the Project drop-down list, choose either your EJB module or Web module.
  4. Select GlassFish in the Categories pane, JDBC Resource in the File Types pane, and click Next.
  5. Select an existing connection pool or create a new one.
  6. (required) Enter a JNDI name for the resource.
  7. Enable or disable the resource by choosing True or False.
  8. Enter a description and click Next.
  9. Enter any properties for the resource.
  10. Click Finish.

To prepare to use a data source:

  1. Ensure the GlassFish application server is running.
  2. Create a web application and select the GlassFish Application Server as the target server.
  3. Access the data source in, for example, a JSP page.

The resource is automatically registered when the project is deployed. When you register the resource, the resource is available to all applications and resources.

For more on working with datasources, see Chapter 5 Data Sources in the Oracle Containers for J2EE Services Guide:

See Also
Registering a Resource with the GlassFish Application Server
Connecting to a Database
About Connection Pools

Legal Notices