Tomcat 数据库连接池配置

配置应该没问题了
不用MyEclipse的tomcat插件 在外面启动tomcat服务 数据池测试成功
不用MyEclipse的tomcat插件 在外面启动tomcat服务 数据池测试成功
但是在MyEclipse里面 使用tomcat 然后open in browser 就出错了
求解
ps:context.xml 还有 web.xml 都配置了 代码查看了N多次了
tomcat是 6.0 数据库是sql 2000
不好意思 你白复制了

ps:不使用数据库连接池 用最原始的方法 能连上

第1个回答  2010-09-01
具体出什么样的错?你不贴出来?

配置server.xml

注:我的web在d:\myweb\myapps

首先要将mysql的驱动程序放到d:\myweb\tomcat5\common\lib下面,一定要放".jar"的文件,如是".zip"的文件直接改为.jar即可。

用文本编辑器打开D:\tomcat5\conf\server.xml,找到结束标志,然后在之前加上如下语句:

<Context path="/myapps" docBase="d:\myweb\myapps" debug="0"
reloadable="true" >

<Resource name="jdbc/DBConnection"
auth="Container"
type="javax.sql.DataSource" />

<ResourceParams name="jdbc/DBConnection">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<!-- Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
-->
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>

<!-- Maximum number of idle dB connections to retain in pool.
Set to 0 for no limit.
-->
<parameter>
<name>maxIdle</name>
<value>3</value>
</parameter>

<!-- Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>

<!-- MySQL dB username and password for dB connections -->
<parameter>
<name>username</name>
<value>root</value>
</parameter>
<parameter>
<name>password</name>
<value>1234</value>
</parameter>

<!-- Class name for mm.mysql JDBC driver -->
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>

<!-- The JDBC connection url for connecting to your MySQL dB.
The autoReconnect=true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
-->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/forumdb?autoReconnect=true</value>
</parameter>
</ResourceParams>

</Context>

再次提醒:一定要放在之前!

配置web.xml

web.xml位于d:\myweb\myapps\WEB-INF下,也即是你的WEB里的web.xml。

同样用文本编辑器打开web.xml,然后加入如下语句(在与之间)

<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/DBConnection</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

查一下dbutils api
第2个回答  2010-09-02
你的MyEclipse里面的tomcat启动正常 报错么?
据我所知Tomcat数据库连接池的配置于IDE没有任何关联的啊~本回答被提问者采纳
相似回答