1、首先要将 mysql 的驱动包放在 tomcat/lib 目录下
2、在 myeclipse 工程目录下的 webroot/META-INF 下新建一个 context.xml 文件,
内容如下:
<Context>
<!--这里是 mysql 的连接池设置-->
## <Resource
### name="jdbc/mysqlds"
### auth="Container"
### type="javax.sql.DataSource"
### driverClassName="com.mysql.jdbc.Driver"
### url="jdbc:mysql://127.0.0.1/blog"
### username="root"
### password="root"
### maxActive="100"
### maxIdle="30"
### maxWait="10000" />##
<!--这里是 oracle 的连接池设置-->
<Resource name="jdbc/oracleds"
## auth="Container"
## type="javax.sql.DataSource"
## maxActive="100"
## maxIdle="30"
## maxWait="10000"
## username="scott"
## password="tiger"
### driverClassName="oracle.jdbc.driver.OracleDriver"
## url="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
## </Context>
3、在需要用连接池的地方使用如下:
mysql 下使用连接池:))
Context ctx = new InitialContext();
## DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/mysqlds");
## Connection conn = ds.getConnection();
oracle 下使用连接池:))