Chapter 13: JDBC Connectivity Preferred Configuration: JNDI Resources Using JNDI resources in Tomcat to configure JDBC data sources is the recommended way to provide Web applications with access to JDBC connections. While other methods are possible (and at least one alternative is discussed later in this chapter), this approach will result in code that is portable to other Web containers over the long term. Following are the steps that must be followed to configure JNDI resources for a JDBC data source: 1. Add a tag in the element (located in the META-INF/context.xmlfile) of the Web application, or in a subelement of the element (in the server.xml file) to configure the JNDI resource. 2. Ensure that a element is defined, corresponding to the from Step 1, in the web.xml file of the Web application using the JDBC resource. 3. Use JNDI calls in the application code to look up the JDBC data source. The following sections provide more detail on how to perform each of these steps. The Resource Tag The tag is used to specify the JNDI resource that represents a JDBC data source. Here is a typical element found in the server.xmlconfiguration file: This resource statement has many attributes. The meaning of each of the attributes is described in the following table. Attribute(s) Description name= jdbc/WroxTC6 Create a JNDI resource that is accessible from the context (logical name) java:comp/env/jdbc/ WroxTC6 by the Web application. The java:comp/ env/portion of the context is added on for all Tomcat- managed contexts. The Web application code can use this context to look up the data source. Table continued on following page
If you looking for unlimited one inclusive web hosting plan please check unlimited web hosting website.
This entry was posted
on Saturday, August 1st, 2009 at 1:20 am and is filed under tomcat.
You can follow any responses to this entry through the RSS 2.0 feed.
Responses are currently closed, but you can trackback from your own site.