编辑应用目录下 META-INF/context.xml 文件(如果没有的话,可以创建一个)
在<Context>...</Context>中加入:
<Resource
name = "jdbc/sw76"
auth = "Container"
type = "javax.sql.DataSource"
driverClassName = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost/sw76"
username = "root"
password = "123456"
maxActive = "10"
maxIdle= "5"
/>
在应用中使用连接池:
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/sw76");
Connection conn = ds.getConnection();