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"  
配置你的应用下的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();   
}