eclipse+myeclipse+mysql+tomcat配置数据源
1 1.配置数据源(Tomcat 5.0\conf\server.xml)在</Host>添加
2 <Context path="/Xxx" docBase="Xxx"
3 debug="5" reloadable="true" crossContext="true">
4 <!--tt为部署工程的名称,
5
6 在C:\Tomcat 5.0\webapps下-->
7 <Logger className="org.apache.catalina.logger.FileLogger"
8 prefix="localhost_tt_log." suffix=".txt"
9 timestamp="true"/>
10
11 <Resource name="jdbc/mysql"
12 auth="Container"
13 type="javax.sql.DataSource"/>
14 <!--jdbc/mysql isjndi name-->
15 <ResourceParams name="jdbc/mysql">
16 <parameter>
17 <name>factory</name>
18 <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
19 </parameter>
20
21 <!-- Maximum number of dB connections in pool. Make sure you
22 configure your mysqld max_connections large enough to handle
23 all of your db connections. Set to 0 for no limit.
24 -->
25 <parameter>
26 <name>maxActive</name>
27 <value>100</value>
28 </parameter>
29
30 <!-- Maximum number of idle dB connections to retain in pool.
31 Set to -1 for no limit. See also the DBCP documentation on this
32 and the minEvictableIdleTimeMillis configuration parameter.
33 -->
34 <parameter>
35 <name>maxIdle</name>
36 <value>30</value>
37 </parameter>
38
39 <!-- Maximum time to wait for a dB connection to become available
40 in ms, in this example 10 seconds. An Exception is thrown if
41 this timeout is exceeded. Set to -1 to wait indefinitely.
42 -->
43 <parameter>
44 <name>maxWait</name>
45 <value>10000</value>
46 </parameter>
47
48 <!-- MySQL dB username and password for dB connections -->
49 <parameter>
50 <name>username</name>
51 <value>root</value>
52 </parameter>
53 <parameter>
54 <name>password</name>
55 <value>root</value>
56 </parameter>
57
58 <!-- Class name for the old mm.mysql JDBC driver - uncomment this entry and comment next
59 if you want to use this driver - we recommend using Connector/J though
60 <parameter>
61 <name>driverClassName</name>
62 <value>org.gjt.mm.mysql.Driver</value>
63 </parameter>
64 -->
65
66 <!-- Class name for the official MySQL Connector/J driver -->
67 <parameter>
68 <name>driverClassName</name>
69 <value>com.mysql.jdbc.Driver</value>
70 </parameter>
71
72 <!-- The JDBC connection url for connecting to your MySQL dB.
73 The autoReconnect=true argument to the url makes sure that the
74 mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
75 connection. mysqld by default closes idle connections after 8 hours.
76 -->
77 <parameter>
78 <name>url</name>
79 <value>jdbc:mysql://localhost:3306/mydb?autoReconnect=true</value>
80 </parameter>
81 </ResourceParams>
82 </Context>
83 <!--mydb数据库名-->
84 2. 修改web.xml
85
86 打开%TOMCAT_HOME%\conf\web.xml,在</web-app>的前面添加以下内容:
87
88 <resource-ref>
89 <description>DB Connection</description>
90 <res-ref-name>jdbc/mysql</res-ref-name>
91 <res-type>javax.sql.DataSource</res-type>
92 <res-auth>Container</res-auth>
93 </resource-ref>
94
95 3. JDBC驱动程序mysql-connector-java-3.0.15-ga-bin.jar放置在%TOMCAT_HOME%\common\lib和应用的WEB-INF\lib下
96
97 启动服务器前,把你的tt部署到C:\Tomcat 5.0\webapps
98 一切OK,启动你的猫猫
2 <Context path="/Xxx" docBase="Xxx"
3 debug="5" reloadable="true" crossContext="true">
4 <!--tt为部署工程的名称,
5
6 在C:\Tomcat 5.0\webapps下-->
7 <Logger className="org.apache.catalina.logger.FileLogger"
8 prefix="localhost_tt_log." suffix=".txt"
9 timestamp="true"/>
10
11 <Resource name="jdbc/mysql"
12 auth="Container"
13 type="javax.sql.DataSource"/>
14 <!--jdbc/mysql isjndi name-->
15 <ResourceParams name="jdbc/mysql">
16 <parameter>
17 <name>factory</name>
18 <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
19 </parameter>
20
21 <!-- Maximum number of dB connections in pool. Make sure you
22 configure your mysqld max_connections large enough to handle
23 all of your db connections. Set to 0 for no limit.
24 -->
25 <parameter>
26 <name>maxActive</name>
27 <value>100</value>
28 </parameter>
29
30 <!-- Maximum number of idle dB connections to retain in pool.
31 Set to -1 for no limit. See also the DBCP documentation on this
32 and the minEvictableIdleTimeMillis configuration parameter.
33 -->
34 <parameter>
35 <name>maxIdle</name>
36 <value>30</value>
37 </parameter>
38
39 <!-- Maximum time to wait for a dB connection to become available
40 in ms, in this example 10 seconds. An Exception is thrown if
41 this timeout is exceeded. Set to -1 to wait indefinitely.
42 -->
43 <parameter>
44 <name>maxWait</name>
45 <value>10000</value>
46 </parameter>
47
48 <!-- MySQL dB username and password for dB connections -->
49 <parameter>
50 <name>username</name>
51 <value>root</value>
52 </parameter>
53 <parameter>
54 <name>password</name>
55 <value>root</value>
56 </parameter>
57
58 <!-- Class name for the old mm.mysql JDBC driver - uncomment this entry and comment next
59 if you want to use this driver - we recommend using Connector/J though
60 <parameter>
61 <name>driverClassName</name>
62 <value>org.gjt.mm.mysql.Driver</value>
63 </parameter>
64 -->
65
66 <!-- Class name for the official MySQL Connector/J driver -->
67 <parameter>
68 <name>driverClassName</name>
69 <value>com.mysql.jdbc.Driver</value>
70 </parameter>
71
72 <!-- The JDBC connection url for connecting to your MySQL dB.
73 The autoReconnect=true argument to the url makes sure that the
74 mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
75 connection. mysqld by default closes idle connections after 8 hours.
76 -->
77 <parameter>
78 <name>url</name>
79 <value>jdbc:mysql://localhost:3306/mydb?autoReconnect=true</value>
80 </parameter>
81 </ResourceParams>
82 </Context>
83 <!--mydb数据库名-->
84 2. 修改web.xml
85
86 打开%TOMCAT_HOME%\conf\web.xml,在</web-app>的前面添加以下内容:
87
88 <resource-ref>
89 <description>DB Connection</description>
90 <res-ref-name>jdbc/mysql</res-ref-name>
91 <res-type>javax.sql.DataSource</res-type>
92 <res-auth>Container</res-auth>
93 </resource-ref>
94
95 3. JDBC驱动程序mysql-connector-java-3.0.15-ga-bin.jar放置在%TOMCAT_HOME%\common\lib和应用的WEB-INF\lib下
96
97 启动服务器前,把你的tt部署到C:\Tomcat 5.0\webapps
98 一切OK,启动你的猫猫