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

Page 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

Image 31
Contents HP Open Source Middleware Stacks Blueprint Copyright 2007 Hewlett-Packard Development Company, L.P Table of Contents Monitor Tomcat with OpenView Tomcat SPI Oracle Database Test Webalizer Usage ReportPage List of Tables Page Intended Audience HP ServicesIntroduction Executive SummaryFeedback@fc.hp.com Typographic ConventionsHP Encourages Your Comments UserInputWeb Server Stack Architecture HP Open Source Web Server Middleware StackWeb Server Stack Architecture Installing the Linux Distribution Installing and Verifying the Linux DistributionRequired Packages and Installation Recommendations YaST Software Selection and System Tasks Verifying the Linux Distribution Installation# /etc/init.d/apache2 start Configuring the Basic Apache Http ServerInstalling and Configuring Sun JDK on an HP Proliant System TomcatFor the alljava.sh file, add the following lines # ln -s /usr/java/jdk1.5.010 /usr/local/jdkFor the alljava.csh file, add the following lines # /usr/local/apache-tomcat/bin/startup.sh Installing and Configuring Tomcat# java -version Following messages appear# /usr/local/apache-tomcat/bin/shutdown.sh Advanced Apache Http Server FeaturesUsing the Apache Http Server Benchmarking Tool If necessary, stop Tomcat by entering the following commandRestart the Apache Http Server for the changes take effect You can correct the error by entering the followingApache Http Server Status and Information Apachemodules definition should now look like the followingApache Server Information web page opens, as shown in Figure Apache Server Status web page opens, as shown in Figure# /etc/init.d/apache2 restart Apache Http Server Log# webalizer For detailed information, see the Webalizer website at Using Virtual Host SupportCreate the following file Configure virtual hosting by creating a file named Using Apache Http Server URL RedirectionOn the second server, create the following Html file Add the following lines to the preceding file Using Apache Http Server Proxy FeaturesEdit the following configuration file Add the following line to the preceding fileCreate the following Html file Error Responses and RedirectsPopulate the preceding file with the following lines Using Per-User Web DirectoriesIntegrating the Web Server Stack Components Configuring the Apache and Tomcat ConnectorHttp//YOURHOSTNAME/jsp-examples Restart Apache by entering the following commandIf there are any errors, check the following log files Insert the following line below the DocumentRoot lineCreate the following test file Integrating the Apache Web Server and PHPIntegrating the Apache Web Server and Perl # rpm -q php5 apache2-modphp5Integrating the Apache Web Server and Python Connecting Tomcat to a DatabaseWeb page displays the following text # tar zxf mysql-connector-java-version.tar.gz Connecting Tomcat and MySQL# /etc/init.d/mysql start # mysqladmin -u root -p create osmsdb# $CATALINAHOME/bin/startup.sh # ps -efgrep mysqldTest page opens as shown in Figure Connecting Tomcat and OracleIf needed, start Tomcat by entering the following command Http//YOURHOSTNAME8080/mysqltest.jspCreating an Oracle Data Source Obtaining and Installing the Oracle Jdbc DriverConfiguring the Oracle Server Testing the Oracle Database ConnectivityOracle Database Test Http//YOURHOSTNAME8080/oracleTest.jsp# mysql -u root -p Password Connecting Tomcat to MySQL or Oracle Using HibernateInstalling Hibernate, Tomcat, and JDK Configuring a Database Driver in TomcatFor an Oracle database server Creating a Simple Application in Tomcat# sqlplus osmsusr/osmspass@osmsdbora For a MySQL database serverAsm.jar asm-attrs.jar antlr-2.7.6rc1.jar File HibernateSessionFactory.class is generated This directory, create a Hibernate Pojo file named Preceding command creates a class file namedHttp//YOURHOSTNAME8080/SimpleDemo/hibernate.jsp Verifying the Simple Application OperationEnabling Https Support in the Apache Http Server Secure the Web Server StackRestart Apache by entering the following Create the following test Html file Apache Http Server AuthorizationApache default document root is Verify that the certificate is displayed as in FigureIf the login fails, the following message appears Protecting Apache Http Server Authorization with Symas CDSConfiguring Apache Http Server Services Html Head Protecting Tomcat Authorization with Symas CDSHtml Head # $CATALINA/bin/shutdown.sh # $CATALINA/bin/startup.sh Monitor Tomcat with OpenView Tomcat SPITomcat SPI Components Software Prerequisites and Reference GuidesPolicies ToolsComplete these steps Complete these steps # /sbin/SuSEfirewall2 stop Appendix B Frequently Asked QuestionsAppendix C Vendor Information Reference Appendix D Hibernate Test Application Source Code Following are the contents of the hibernate.jsp filePage Appendix D Hibernate Test Application Source Code