Procedure for configuring the MySQL Data Source in Tomcat 5

Source: Internet
Author: User

This article mainly describes how to correctly configure the actual operation process of the MySQL data source and its actual application code in tomcat5. if you are crazy about MySQL databases, you can get a better understanding of the following articles.

1. Configure MySQL environment variables:

Softe version: tomcat (a very useful JSP running platform) 5.0.12/MySQL (the best combination with PHP) 4.1.7/MySQL (the best combination with PHP) _ driver ---

MySQL (best combination with PHP)-connector-java-3.1.4-beta-bin.jar

The MySQL (best combination with PHP) driver can be downloaded from the official website www. MySQL (the best combination with PHP). com

Path:

Tomcat (a very useful JSP running platform) 5 in d: mywebomcat5;

MySQL (the best combination with PHP) in C: Program FilesMySQL (the best combination with PHP) MySQL (the best combination with PHP) Server 4.1

Path (added on the basis of the original ):

D: mywebomcat5in; d: mywebjdk1.4; d: myweb

Jdk1.4in;

D: mywebomcat5commonlibservlet-api.jar; C: Program Files

MySQL (the best combination with PHP) Server4.1in

CLASSPATH: d: mywebomcat5commonlibservlet-api.jar; d: myweb

Tomcat (a very useful JSP running platform) 5 commonlibjsp (preferred for SUN Enterprise Applications)-api. jar

JAVA_HOME: d: mywebjdk1.4

CATALINA_HOME: d: mywebomcat5

2. Establish a Test Database

Create a forumdb database in MySQL (the best combination with PHP) and create a table member as follows:

 
 
  1. create database forumdb;  
  2. create table member  
  3. (  
  4. id int,  
  5. name varchar(6)  
  6. ); 

Insert the following two test data:

 
 
  1. insert into member values(1,"zhang");  
  2. insert into member values(2,"wang"); 

Now, the database is ready.

Iii. Configure MySQLserver. xml (standardization is getting closer and closer)

Note: My web in d: mywebmyapps

First, put the MySQL Driver (the best combination with PHP) under d: mywebomcat5commonlib ". jar files, such ". the zip file is changed. jar.

Open D: omcat5confserver. xml in a text editor (standardization is getting closer and closer), locate the end mark, and add the following statement before:

 
 
  1. <Context path = "/myapps" docBase = "d: mywebmyapps" debug = "0"
  2. Reloadable = "true">
  3. <Resource name = "jdbc/DBConnection"
  4. Auth = "Container"
  5. Type = "javax. SQL. DataSource"/>
  6. <ResourceParams name = "jdbc/DBConnection">
  7. <Parameter>
  8. <Name> factoryname>
  9. <Value> org. apache (the most popular WEB server platform on the Unix platform). commons. dbcp. BasicDataSourceFactoryvalue>
  10. Parameter>
  11.  
  12. MaxActive  
  13. 10  
  14.  
  15.  
  16. MaxIdle  
  17. 3  
  18.  
  19.  
  20. MaxWait  
  21. 10000  
  22.  
  23.  
  24. <Parameter>
  25. <Name> usernamename>
  26. <Value> rootvalue>
  27. Parameter>
  28. <Parameter>
  29. <Name> passwordname>
  30. <Value> 1234 value>
  31. Parameter>
  32.  
  33. <Parameter>
  34. <Name> driverClassNamename>
  35. <Value> com. MySQL (the best combination with PHP). jdbc. Drivervalue>
  36. Parameter>
  37. MySQL (the best combination with PHP) dB.
  38. The autoReconnect = true argument to the url makes sure that
  39. Mm. MySQL (the best combination with PHP) JDBC Driver will automatically reconnect if MySQL (the best combination with PHP) d closed
  40. Connection. MySQL (the best combination with PHP) d by default closes idle connections after 8 hours.
  41. -->
  42. <Parameter>
  43. <Name> urlname>
  44. <Value> jdbc: MySQL (the best combination with PHP): // localhost: 3306/forumdb? AutoReconnect = truevalue>
  45. Parameter>
  46. ResourceParams>
  47. Context>
  48.  

The above content describes how to configure the MySQL Data Source in Tomcat 5, hoping to help you in this regard.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.