Accessing a Connection Pool from a Java Class

See Also

Applications that are deployed to servers often need to access databases that reside on remote machines. You therefore have to set up a JDBC connection pool on the server that points to the database. You then create a data source that connects to the connection pool and use the data source's JNDI name to acquire a connection to the database.

To access a database from an enterprise application:

  1. (Optional) Create a service locator class to handle getting the reference to the database.
  2. Open the Java file from which you want to access the database. In the Source Editor, right-click the file and choose Insert Code > Use Database.
  3. Enter a JNDI name for the database connection. This name must be the same as the JNDI name of the JDBC data source for the database on the target server.
  4. Select the database to which you want to connect in the Connection drop-down list. If the database is not listed, do the following:
    1. If the JDBC driver for the database server is not registered in the IDE, click Add Driver.
    2. Click Add Connection to connect to the database.
  5. Under Service Locator Strategy, specify whether to generate inline lookup code or use an existing service locator. You can click the Browse to search for the service locator class name.
  6. Click OK.
See Also
About Connection Pools
Using a Service Locator
Connecting to a Database
Adding a New JDBC Driver

Legal Notices