工大后院

 找回密码
 加入后院

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 2334|回复: 9

Tomcat 6.0.10怎么配置连接池

[复制链接]
发表于 2007-4-6 08:59 | 显示全部楼层 |阅读模式
我不知道怎么配置连接池。。配置几次都不成功。。
谁会的,教教我。。谢谢。。。

注意,版本是Tomcat 6.0.10

不要转载网上的文章。。如果你没有试过就算了。。
发表于 2007-4-6 09:34 | 显示全部楼层
看到楼上的最后一句话,真不太敢回帖啊!

我上学期做过,现在也忘记了步骤,不过我做的时候就是参考这里(http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html)的,楼主有兴趣也可以参考下,没兴趣就算了。
回复

使用道具 举报

 楼主| 发表于 2007-4-6 13:40 | 显示全部楼层
...我就是看过那个之后还是不成功。。所以看有没有试过。。[em06]
回复

使用道具 举报

发表于 2007-4-7 01:47 | 显示全部楼层
http://gdutbbs.com/viewthread.php?tid=35166&highlight=jndi

以前写的。。。不知有没有用。。。
回复

使用道具 举报

发表于 2007-4-15 18:49 | 显示全部楼层
毕业设计即将开始,今天用了tomcat-6.0.10成功配置了连接池。
离楼主提问的时间很久了,还是贴出来,希望还有点用处。

步骤几乎完全参考官方文档(http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html)。
所以这里只提示两点:
1、mysql的JDBC驱动包要下载放到“tomcat-6.0.10/lib”目录下
2、测试程序用到了JSTL,所以也要下载JSTL包。
3、Context 标签是放在Host之间。

PS:如果按照以下步骤还不成功,可以留下Email,我把自己配置成功的打包发过去。
MySQL DBCP Example
0. Introduction
Versions of MySQL and JDBC drivers that have been reported to work:

MySQL 3.23.47, MySQL 3.23.47 using InnoDB,, MySQL 3.23.58, MySQL 4.0.1alpha
Connector/J 3.0.11-stable (the official JDBC Driver)
mm.mysql 2.0.14 (an old 3rd party JDBC Driver)

Before you proceed, don't forget to copy the JDBC Driver's jar into $CATALINA_HOME/lib.

1. MySQL configuration
Ensure that you follow these instructions as variations can cause problems.

Create a new test user, a new database and a single test table. Your MySQL user must have a password assigned. The driver will fail if you try to connect with an empty password.
   
  1. mysql> GRANT ALL PRIVILEGES ON *.* TO javauser@localhost
  2.     ->   IDENTIFIED BY 'javadude' WITH GRANT OPTION;
  3. mysql> create database javatest;
  4. mysql> use javatest;
  5. mysql> create table testdata (
  6.     ->   id int not null auto_increment primary key,
  7.     ->   foo varchar(25),
  8.     ->   bar int);
复制代码

   

Note: the above user should be removed once testing is complete!

Next insert some test data into the testdata table.
   
  1. mysql> insert into testdata values(null, 'hello', 12345);
  2. Query OK, 1 row affected (0.00 sec)

  3. mysql> select * from testdata;
  4. +----+-------+-------+
  5. | ID | FOO   | BAR   |
  6. +----+-------+-------+
  7. |  1 | hello | 12345 |
  8. +----+-------+-------+
  9. 1 row in set (0.00 sec)
  10. [/quote]


  11. 2. server.xml configuration
  12. Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to $CATALINA_HOME/conf/server.xml.

  13. Add this in between the </Context> tag of the examples context and the </Host> tag closing the localhost definition. If there is no such tag, you can add one as illustrated in the Context and Host configuration references, and repeated below for your convenience.
  14.    
  15. [code]<Context path="/DBTest" docBase="DBTest"
  16.         debug="5" reloadable="true" crossContext="true">
  17.   <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
  18.                maxActive="100" maxIdle="30" maxWait="10000"
  19.                username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
  20.                url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>
  21. </Context>
复制代码


3. web.xml configuration
Now create a WEB-INF/web.xml for this test application.
   
  1. <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  2.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  4. http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
  5.     version="2.4">
  6.   <description>MySQL Test App</description>
  7.   <resource-ref>
  8.       <description>DB Connection</description>
  9.       <res-ref-name>jdbc/TestDB</res-ref-name>
  10.       <res-type>javax.sql.DataSource</res-type>
  11.       <res-auth>Container</res-auth>
  12.   </resource-ref>
  13. </web-app>
复制代码


4. Test code
Now create a simple test.jsp page for use later.

  1.   
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
  3. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

  4. <sql:query var="rs" dataSource="jdbc/TestDB">
  5. select id, foo, bar from testdata
  6. </sql:query>

  7. <html>
  8.   <head>
  9.     <title>DB Test</title>
  10.   </head>
  11.   <body>

  12.   <h2>Results</h2>
  13.   
  14. <c:forEach var="row" items="${rs.rows}">
  15.     Foo ${row.foo}<br/>
  16.     Bar ${row.bar}<br/>
  17. </c:forEach>

  18.   </body>
  19. </html>
复制代码

That JSP page makes use of JSTL's SQL and Core taglibs. You can get it from Sun's Java Web Services Developer Pack or Jakarta Taglib Standard 1.1 project - just make sure you get a 1.1.x release. Once you have JSTL, copy jstl.jar and standard.jar to your web app's WEB-INF/lib directory.

Finally deploy your web app into $CATALINA_HOME/webapps either as a warfile called DBTest.war or into a sub-directory called DBTest

Once deployed, point a browser at http://localhost:8080/DBTest/test.jsp to view the fruits of your hard work.
回复

使用道具 举报

发表于 2007-4-15 19:54 | 显示全部楼层
由于老师要求用MSSQL,所以在成功配置mysql后,作点小修改。

我用的是MSSQL2000,并打上了SP4补丁。然后用google搜索,到微软网上下载JDBC for MSSQL2000的驱动。

方法同上,把“msbase.jar、mssqlserver.jar、msutil.jar”放到”tomcat-6.0.10\lib“目录下。


配置文件和前面的MYSQL差不多,如下所示:

  1.   <Context path="/Test" docBase="E:/jsp/languages"
  2.     debug="0" reloadable="true" crossC>
  3.     <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
  4.         maxActive="100" maxIdle="30" maxWait="10000"
  5.         username="sa" password="" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
  6.         url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Test"/>
  7.   </Context>
复制代码


以上作为笔记。
回复

使用道具 举报

 楼主| 发表于 2007-4-16 02:19 | 显示全部楼层
好的,我看看先。
回复

使用道具 举报

 楼主| 发表于 2007-4-16 03:32 | 显示全部楼层
配置mysql那个成功了。。 。。以前不知道怎么配置的,就是不行。。现在好了,等下试试SQL SERVER。。
回复

使用道具 举报

 楼主| 发表于 2007-4-16 04:52 | 显示全部楼层
sql server也连接成功了。。谢谢各位!!
回复

使用道具 举报

发表于 2007-4-16 09:38 | 显示全部楼层
恭喜恭喜!!!

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入后院

本版积分规则

QQ|Archiver|手机版|小黑屋|广告业务Q|工大后院 ( 粤ICP备10013660号 )

GMT+8, 2025-5-15 10:39

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表