HP 5991-5565 manual Connecting Tomcat and MySQL, # tar zxf mysql-connector-java-version.tar.gz

Models: 5991-5565

1 57
Download 57 pages 47.29 Kb
Page 31
Image 31

Figure 11 Tomcat Connections Using JDBC

Tomcat uses the data-source concept to create database connections. A data source must be configured in an XML configuration file. The data source provides details about the target database, such as the database server IP address and login credentials. The JDBC driver connects to the database and the username/password combination is used to login to the database. For Tomcat 5.5, a data source is configured either in $CATALINA_HOME/conf/context.xml or in /META-INF/context.xmlwithin the web applications. By default, the data source support in Tomcat is based on the Database Connection Pool (DBCP), which is used to create active connections and manage the lifecycle of the individual connections automatically.

Connecting Tomcat and MySQL

MySQL is the leading open source database, and is used widely for web application middleware environments. MySQL stores relational data and enables fast, simple access and updates to stored data through the standard JDBC APIs. These APIs are supplied by MySQL in the form of the Connector/J software. This section describes the steps to connect Tomcat to MySQL.

Obtaining and Installing the JDBC Drivers

Perform the following steps on the Tomcat web server:

1.Download the MySQL JDBC driver 5.0 from the MySQL website: http://dev.mysql.com/downloads/connector/j/5.0.html

2.Unzip the downloaded packages by entering the following command:

#tar zxf mysql-connector-java-<version>.tar.gz

3.Install the JDBC driver for Tomcat by entering the following command:

#cp mysql-connector-java-<version>-.jar $CATALINA_HOME/common/lib

Creating a New Data Source

To create a data source binding for a JDBC driver, perform the following steps on the Tomcat web server:

Installing, Configuring, and Managing Web Server Middleware Stack Components 31

Page 31
Image 31
HP 5991-5565 manual Connecting Tomcat and MySQL, # tar zxf mysql-connector-java-version.tar.gz