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:
- create database forumdb;
- create table member
- (
- id int,
- name varchar(6)
- );
Insert the following two test data:
- insert into member values(1,"zhang");
- 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:
- <Context path = "/myapps" docBase = "d: mywebmyapps" debug = "0"
- Reloadable = "true">
- <Resource name = "jdbc/DBConnection"
- Auth = "Container"
- Type = "javax. SQL. DataSource"/>
- <ResourceParams name = "jdbc/DBConnection">
- <Parameter>
- <Name> factoryname>
- <Value> org. apache (the most popular WEB server platform on the Unix platform). commons. dbcp. BasicDataSourceFactoryvalue>
- Parameter>
-
-
- MaxActive
- 10
-
-
-
- MaxIdle
- 3
-
-
-
- MaxWait
- 10000
-
-
- <Parameter>
- <Name> usernamename>
- <Value> rootvalue>
- Parameter>
- <Parameter>
- <Name> passwordname>
- <Value> 1234 value>
- Parameter>
-
- <Parameter>
- <Name> driverClassNamename>
- <Value> com. MySQL (the best combination with PHP). jdbc. Drivervalue>
- Parameter>
- MySQL (the best combination with PHP) dB.
- The autoReconnect = true argument to the url makes sure that
- Mm. MySQL (the best combination with PHP) JDBC Driver will automatically reconnect if MySQL (the best combination with PHP) d closed
- Connection. MySQL (the best combination with PHP) d by default closes idle connections after 8 hours.
- -->
- <Parameter>
- <Name> urlname>
- <Value> jdbc: MySQL (the best combination with PHP): // localhost: 3306/forumdb? AutoReconnect = truevalue>
- Parameter>
- ResourceParams>
- Context>
-
The above content describes how to configure the MySQL Data Source in Tomcat 5, hoping to help you in this regard.