一
把数据库JDBC驱动拷贝到
%TOMCAT_HOME%/common/lib
或
%TOMCAT_HOME%/webapps/yourweb/WEBINF/lib 下;
修改tomcat安装目录下conf/serverxml在Host元素下添加一个Context元素示例:
< Context path=/TomcatPool docBase=E:\\Tomcat \\webapps\\TomcatPool debug= reloadable=true>
< Resource name=jdbc/ds type=javaxsqlDataSource
driverClassName=commicrosoftjdbcsqlserverSQLServerDriver
url=jdbc:microsoft:sqlserver://localhost:;databasename=pubs
username=sa password=sa
maxWait= maxActive=
maxIdle=/>
< /Context>
修改TomcatPool工程的web
xml
添加一个resource
ref元素
< resourceref>
< description>sqlserverDB connection< /description>
< resrefname>jdbc/ds< /resrefname>
< restype>javaxsqlDataSource< /restype>
< resauth>Container< /resauth>
< /resourceref>
调用
javaxnamingContext context = new javaxnamingInitialContext();
javaxsqlDataSource ds = (javaxsqlDataSource)contextlookup(java:comp/env/jdbc/ds);
javasqlConnection conn = dsgetConnection();
对于Tomcat 步骤为
以前的版本要到serverxml中配置版本以后要到contextxml中配置
在下只能用这个配置:
< Context docBase=MyZhiNangTuanDemo path=/MyZhiNangTuanDemo reloadable=true>
< Resource name=jdbc/mldn auth=Container
type=javaxsqlDataSource maxActive= maxIdle=
maxWait= username=root password=
driverClassName=commysqljdbcDriver
url=jdbc:mysql://localhost:/mldn/>
< ResourceLink global=jdbc/mldn name=jdbc/mldn type=javaxsqlDataSource/>
< /Context>
应用程序的wen
xml也不用配置这个了
< resourceref>
< description>DB Connection< /description>
< resrefname>jdbc/mldn< /resrefname>
< restype>javaxsqlDataSource< /restype>
< resauth>Container< /resauth>
< /resourceref>