tomcat jndi数据库连接池配置

tomcat 配置文件conf/content.xml
<content></content>里加入
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30"   
         maxWait="10000" 
        username="user"       password="123456" 
        driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" 
       url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=dbname" />


项目配置文件WEB-INF/web.xml
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/testdb</res-ref-name>
<res-type>com.microsoft.sqlserver.jdbc.SQLServerDriver</res-type>
<res-auth>Container</res-auth>
</resource-ref> 
</web-app>


项目src/conf.properties文件配置
driver.sqlserver=net.sourceforge.jtds.jdbc.Driver
dbjndi.read.default=java:comp/env/jdbc/testdb
dbjndi.write.default=java:comp/env/jdbc/testdb
在tomcat 的lib加入相应包
mssql包有3个:msbase,mssqlserver,msutil

猜你喜欢

转载自hq369.iteye.com/blog/1746013