Chapter 6: Advanced Tomcat Features The next section shows how to apply these elements to configure a JDBC DataSource and JavaMail session. Configuring a JDBC DataSource JDBC features, including connections pooling, are directly supported by Tomcat 6. JDBC is discussed at length in Chapter 13 . For now, it is necessary to know only how JDBC connections (as a JNDI resource) can be passed to Web applications. Your JDBC driver can be placed in the $CATALINA_HOME/lib/ directory. This enables the Tomcat server and your applications to find and access this driver. Finally, you must configure the JNDI resource factory using and elements. In this case, you are configuring the database factory to use the MySQL database, with an application-wide scope. This instance of the DataSource will be available only to the associated application. The definition needs to be placed into a context.xmlfile under the webapps/ [application name]/META-INFdirectory: … This segment configures Tomcat s built-in JDBC DataSource factory. The built-in DataSource factory implementation in Tomcat is org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory . A DataSource factory is a class from which new instances of DataSource objects can be obtained. With this factory, the configuration parameters described in the following table are possible. Parameter Description driverClassName maxActive maxIdle maxWait user password url validationQuery Java programming language class name of the JDBC driver. This driver should be placed in the $CATALINA_HOME/lib directory for easy location by the DataSource factory code. The maximum number of active connections in this pool. The maximum number of idle connections in this pool. In milliseconds, indicates the maximum wait for a connection by the DataSource factory before throwing an exception. The user ID used to log on to the database. The password used to log on to the database. The JDBC-compatible URL specifies the database instance to be used. An optional SQL query used to validate a connection. Essentially, the factory will perform this query to ensure that rows are returned before considering the connection valid. For example, you can parameterize the defined JDBC resource by using the following elements:
For high quality jboss hosting services please check jboss web hosting website.
This entry was posted
on Thursday, March 19th, 2009 at 9:15 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.