天天看点

Tomcat 6.0.18 配置数据源

第一步:在%Tomcat_HOME%conf\context.xml的 Context 标签里添加如下代码:

<Resource  name="jdbc/starnet" auth="Container" type="javax.sql.DataSource"
     		username="myuser"
     		password="123456"
     		url="jdbc:mysql://localhost:3306/test"
     		driverClassName="com.mysql.jdbc.Driver"
     		maxIdle="30"
     		maxWait="5000"
     		maxActive="100"/> 
           

 第二步:配置应用目录下的web.xml文件,在<web-app></web-app>之间加入以下代码:

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

注意:要求<res-ref-name>jdbc/starnet</res-ref-name>中的“jdbc/starnet”一定要与在context.xml中配置的Resource中的name一致,不然会出错。