background image

Resource Connections

<< Transactions in Web Components | DataSource Objects and Connection Pools >>
<< Transactions in Web Components | DataSource Objects and Connection Pools >>

Resource Connections

Resource Connections
Java EE components can access a wide variety of resources, including databases, mail sessions,
Java Message Service objects, and URLs. The Java EE 5 platform provides mechanisms that
allow you to access all these resources in a similar manner. This chapter describes how to get
connections to several types of resources.
Resources and JNDI Naming
In a distributed application, components need to access other components and resources such
as databases. For example, a servlet might invoke remote methods on an enterprise bean that
retrieves information from a database. In the Java EE platform, the Java Naming and Directory
Interface (JNDI) naming service enables components to locate other components and
resources.
A resource is a program object that provides connections to systems, such as database servers
and messaging systems. (A JDBC resource is sometimes referred to as a data source.) Each
resource object is identified by a unique, people-friendly name, called the JNDI name.
For example, the JNDI name of the JDBC resource for the Java DB database that is shipped with
the Application Server is jdbc/__default.
An administrator creates resources in a JNDI namespace. In the Application Server, you can use
either the Admin Console or the asadmin command to create resources. Applications then use
annotations to inject the resources. If an application uses resource injection, the Application
Server invokes the JNDI API, and the application is not required to do so. However, it is also
possible for an application to locate resources by making direct calls to the JNDI API.
A resource object and its JNDI name are bound together by the naming and directory service.
To create a new resource, a new name-object binding is entered into the JNDI namespace.
For information on creating Java Message Service (JMS) resources, see
"Creating JMS
Administered Objects for the Synchronous Receive Example" on page 915
. For an example of
creating a JDBC resource, see
"Creating a Data Source in the Application Server" on page 98
.
34
C H A P T E R
3 4
1009