2 web.xml
3 在工程WebRoot下的META-INF文件夹下新建xml文件 context.xml
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/bookstore?autoReconnect=true"/>
这样 部署工程后 在tomcat\conf\Catalina\localhost 下面会生成 工程名。xml
内容跟 context.xml的内容一样
4 使用方法
import javax.sql.*;
import javax.naming.*;
……
……
Context ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/bookstore");
conn=ds.getConnection();
……
……
catch(NamingException ne)
{
ne.printStackTrace();
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|