posts - 2, comments - 27, trackbacks - 0, articles - 60
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Tomcat6 数据连接池配置

Posted on 2009-03-06 15:47 ZhouFeng 阅读(352) 评论(0)  编辑  收藏 所属分类: 转载Web服务器
Tomcat6 和 Tomcat5的配置不一样,我按Tomcat5的配置方法,就是报错,以前是把配置写在server.xml里,但在Tomcat6里面是把配置写在conf/context.xml里
把数据库驱动放到lib目录下
配置tomcat下的conf下的context.xml文件,在<context></context>之间添加连接池如下
 <Resource name="jdbc/mysql"  
    auth
="Container"  
    type
="javax.sql.DataSource"  
    driverClassName
="com.mysql.jdbc.Driver"  
    url
="jdbc:mysql://localhost/test"  
    username
="root"  
    password
="root"  
    maxActive
="100"  
    maxIdle
="30"  
    maxWait
="10000" />
配置你的应用下的web.xml中的<web-app></web-app>之间加入
<resource-ref>  
    
<description>DB Connection</description>  
    
<res-ref-name>jdbc/mysql</res-ref-name>  
    
<res-type>javax.sql.DataSource</res-type>  
    
<res-auth>Container</res-auth>  
</resource-ref> 
配置好了之后就可以通过下面的方式获取数据库连接
DataSource ds = null;   
try{   
    InitialContext ctx
=new InitialContext();   
    ds
=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");   
    Connection conn 
= ds.getConnection();
    
}
catch(Exception ex){   
    ex.printStackTrace();   
}



只有注册用户登录后才能发表评论。


网站导航: