在tomcat的context.xml中追加以下内容
在连接类中添加:
<Resource name = "jdbc/251DCPF"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:MySQL://10.1.128.251:3306/dcpf30"
username="uidcpf30"
password="dcpf30pwd"
maxActive="20"
maxIdle="0"
maxWait="30000"/>
在连接类中添加:
public static Connection getConn() throws ClassNotFoundException,
SQLException, NamingException {
// 实现数据连接池
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(config.getDBName());
//config.getDBName()用来获得 resource中name的值
Connection con = ds.getConnection();
return con;
}