Connecting to MySQL


Using Resin's JNDI Configuration

The Resin server supports the use of Java Naming and Directory Interface (JNDI). JNDI provides an application with a global naming tree designed for storing factory objects and configuration variables. The goal is the extreme separation of configuration information from an application. An application can use JNDI to pull a factory object and grab an object for use by the application. By using a configuration file, you can exchange databases with little fanfare and—more importantly—without any changes to the source code.

Basic Configuration Parameters

The basic database configuration uses the <database> element as a number of sub-elements. A complete list of the sub-elements can be found in Chapter 15. Following are the most used ones:

  • <name>— The JNDI path relative to java:comp/env.

  • <driver-class>— The JDBC driver class. (Required)

  • <driver-url>— The location of the database as either an IP, localhost, or domain name. (Required)

  • <user>— Default is an empty string. The username to use when connecting to the database.

  • <password>— Default is an empty string. The password to use when connecting to the database.

  • <max-connections>— Default is 20. The maximum number of allowed connections to the database.

Library Placement

When you're using the JNDI configuration, you must place the driver class or JAR in an appropriate location where the server can find it. As you saw earlier in the chapter, one of the first places the system attempts to find the driver is on the global classpath. If the driver isn't on the classpath, the system looks in the /lib directory of the server. In most cases, this is the best place to put the driver because it is specific to the server. You have the option of putting the driver in the application's WEB-INF/lib or WEB-INF/classes directory if you want it to be more aligned with the specific application.

Using the Configuration

The JNDI information is put into the Resin configuration file under the <database> element. The database connectivity information used in Listing 11.1 can be converted into a JNDI configuration as shown here:

 <database>     <jndi-name>jdbc/mysql</jndi-name>     <driver type="org.gjt.mm.mysql.Driver">     <url>       jdbc:mysql://localhost:3306/products     </url>     <user>spider</user>     <password>spider</password>     </driver>     <max-connections>20</max-connections>     <max-idle-time>30s</max-idle-time>   </database> 

You place this configuration in the resin.conf configuration file for access by an application.




Mastering Resin
Mastering Resin
ISBN: 0471431036
EAN: 2147483647
Year: 2002
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net