免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1400 | 回复: 0
打印 上一主题 下一主题

Tomcat6.0连接池配置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-10 10:09 |只看该作者 |倒序浏览
  • 1.配置tomcat下的conf下的context.xml文件,在之间添加连接池配置:   
  • 1.  "jdbc/oracle"  
  • 2.         auth="Container"     
  • 3.         type="javax.sql.DataSource"     
  • 4.         driverClassName="oracle.jdbc.driver.OracleDriver "     
  • 5.         url=" jdbc:oracle:thin:@host:port:databse"     
  • 6.         username=" user "     
  • 7.         password="password"     
  • 8.         maxActive="100"     
  • 9.         maxIdle="30"     
  • 10.        maxWait="10000" />     
  • 2.配置你的应用下的web.xml中的之间加入:  
  • 1.      
  • 2.      DB Connection     
  • 3.      jdbc/oracle     
  • 4.      javax.sql.DataSource     
  • 5.      Container     
  • 6.         
  • 3.把连接数据库的第三方驱动放到common/lib下面就ok了  
  • 4.测试程序我就不写了  
  •   
  • Tomcat5.5x连接池配置  
  •   
  • 方式一、全局数据库连接池  
  • 1、通过管理界面配置连接池,或者直接在tomcat\conf\server.xml的GlobalNamingResources中增加  
  • "jdbc/mydb" type="javax.sql.DataSource" password="mypwd" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" maxIdle="2" maxWait="5000" validationQuery="select 1" username="sa" url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb" maxActive="4"/>  
  • 2、在tomcat\webapps\myapp\META-INF\context.xml的Context中增加:  
  • "jdbc/mydb" name="jdbc/mydb" type="javax.sql.DataSource"/>  
  • 这样就可以了。  
  • 方式二、全局数据库连接池  
  • 1、同上  
  • 2、在tomcat\conf\context.xml的Context中增加:  
  • "jdbc/mydb" name="jdbc/mydb" type="javax.sql.DataSource"/>  
  • 方式三、局部数据库连接池  
  • 只需在tomcat\webapps\myapps\META-INF\context.xml的Context中增加:  
  • "jdbc/mydb" type="javax.sql.DataSource" password="mypwd" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" maxIdle="2" maxWait="5000" validationQuery="select 1" username="sa" url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb" maxActive="4"/>  
  • 参数说明:  
  • driveClassName:JDBC驱动类的完整的名称;   
  • maxActive:同时能够从连接池中被分配的可用实例的最大数;   
  • maxIdle:可以同时闲置在连接池中的连接的最大数;   
  • maxWait:最大超时时间,以毫秒计;   
  • password:用户密码;   
  • url:到JDBC的URL连接;   
  • user:用户名称;   
  • validationQuery:用来查询池中空闲的连接。  
  • 以上三种方式在tomcat 5.5.4下都可以。另外,sql server的jdbc driver是从微软网站上下载的sql server jdbc (sp3)。  
  •   
  • tomcat5.0连接池配置  
  • 在tomcat 的下面路径(Tomcat \conf\Catalina\localhost)下建一个xml文件,内容如下  
  • "jdbc/test" auth="Container" type="javax.sql.DataSource"/>  
  •     "jdbc/test">  
  •          
  •             factory  
  •             org.apache.commons.dbcp.BasicDataSourceFactory  
  •          
  •         
  •              configure your mysqld max_connections large enough to handle  
  •              all of your db connections. Set to 0 for no limit.  
  •              -->  
  •          
  •             maxActive  
  •             100  
  •          
  •         
  •              Set to 0 for no limit.  
  •              -->  
  •          
  •             maxIdle  
  •             30  
  •          
  •         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.  
  •              -->  
  •          
  •             maxWait  
  •             10000  
  •          
  •         for dB connections  -->  
  •          
  •             username  
  •             sa  
  •          
  •          
  •             password  
  •             test  
  •          
  •         for JDBC driver -->  
  •          
  •             driverClassName  
  •             net.sourceforge.jtds.jdbc.Driver  
  •          
  •         
  •              Hibernate work.  Or you can remove calls to commit(). -->  
  •          
  •             defaultAutoCommit  
  •             true  
  •          
  •         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.  
  •              -->  
  •          
  •             url  
  •             jdbc:jtds:sqlserver://url/filedb;charset=gb2312;autoReconnect=true  
  •          
  •          
  •          
  •             removeAbandoned  
  •             true  
  •          
  •         
  •              before it is considered abandoned.   
  •              -->  
  •          
  •             removeAbandonedTimeout  
  •             60  
  •          
  •         
  •              connection resources.   
  •              -->  
  •          
  •             logAbandoned  
  •             true  
  •          
  •       
                   
                   
                   

    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/59737/showart_1991472.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP