1.把数据库JDBC驱动拷贝到%TOMCAT_HOME%/common/lib和%TOMCAT_HOME%/webapps/yourweb/WEB-INF/lib下
2.修改tomcat安装目录下conf/server.xml,在Host元素下添加一个Context元素,示例:
<Context path="/TomcatPool" docBase="E:\\Tomcat 5.5\\webapps\\TomcatPool" debug="1" reloadable="true">
<Resource name="jdbc/ds" type="javax.sql.DataSource"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs"
username="sa" password="sa"
maxWait="5000" maxActive="4"
maxIdle="4"/>
</Context>
3.修改TomcatPool工程的web.xml,添加一个resource-ref元素
<resource-ref>
<description>sqlserverDB connection</description>
<res-ref-name>jdbc/ds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
4.调用
javax.naming.Context context = new javax.naming.InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)context.lookup("java:comp/env/jdbc/ds");
java.sql.Connection conn = ds.getConnection();
posted on 2007-12-14 16:34
terryliu 阅读(162)
评论(0) 编辑 收藏 所属分类:
java