1.在%Tomcat 6.0%\conf\Catalina\localhost目录下新建一个xml文件,文件名为工程名
<?xml version='1.0' encoding='utf-8'?>
<Context>
<Resource name="SQLServerDB"
auth="Container"
type="javax.sql.DataSource"
maxActive="20"
maxIdel="10"
maxWait="1000"
username="sa"
password="sa"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost:1433/database;tds=8.0;lastupdatecount=true"
poolPreparedStatements="true"
defaultAutoCommit="true" >
</Resource>
</Context>
2.将所需要的jtds jar包拷到tomcat目录下lib中
3.在工程的web.xml中增加
<resource-ref>
<description>sample</description>
<res-ref-name>SQLServerDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
OK,步骤完成
注意:如过不成功,在conf/server.xml中<GlobalNamingResources></GlobalNamingResources>标签下添加
<Resource name="SQLServerDB"
auth="Container"
type="javax.sql.DataSource"
maxActive="20"
maxIdel="10"
maxWait="1000"
username="sa"
password="sa"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost:1433/database;tds=8.0;lastupdatecount=true"
poolPreparedStatements="true"
defaultAutoCommit="true" >
</Resource>
必须同第一步内容形同,否则报出异常:
'Cannot create JDBC driver of class '' for connect URL 'null'
在调用时,JNDI名为java:comp/env/SQLServerDB(适用于tomcat) |