首页 > 代码库 > tomcat+oracle连接池
tomcat+oracle连接池
tomcat 5.5.23
oracle 10g
全局配置
一.tomcat目录\common\lib下添加包ojdbc14.jar.
二.tomcat目录\conf\server.xml的<GlobalNamingResources>标签中插入
oracle的连接参数:
<Resource name="jdbc/oracle"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxIdle="10"
maxWait="5000"
maxActive="20"
username="onepiece"
password="12345"
url="jdbc:oracle:thin:@localhost:1521:orcl"
/>
(name为jdbc/oracle后面还要用到)
三.tomcat目录\Catalina\localhost的web配置文件如hello.xml,
原来为:
<Context path="hello" docBase="D:\workspace\HelloOracle\web" reloadable="true"
privileged="true" antiResourceLocking="false" antiJARLocking="false">
</Context>
改为
<Context path="hello" docBase="D:\workspace\HelloOracle\web" reloadable="true"
privileged="true" antiResourceLocking="false" antiJARLocking="false">
<ResourceLink global="jdbc/oracle" name="jdbc/oracle" type="javax.sql.DataSource"/>
</Context>
即加入:
<ResourceLink global="jdbc/oracle" name="jdbc/oracle" type="javax.sql.DataSource"/>
四.应用(注意名字jdbc/oracle):
InitialContext icont = new InitialContext();
DataSource dataSource = (DataSource) icont.lookup("java:comp/env/jdbc/oracle");
conn = dataSource.getConnection();
即可以获取连接了
局部配置(只有hello application可以应用)
一.同上第一步
二.见上第三步,但改的不一样
原来为:
<Context path="hello" docBase="D:\workspace\HelloOracle\web" reloadable="true"
privileged="true" antiResourceLocking="false" antiJARLocking="false" />
改为
<Context path="hello" docBase="D:\workspace\HelloOracle\web" reloadable="true"
privileged="true" antiResourceLocking="false" antiJARLocking="false">
<Resource name="jdbc/oracle"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxIdle="10"
maxWait="5000"
maxActive="20"
username="onepiece"
password="12345"
url="jdbc:oracle:thin:@localhost:1521:orcl"
/>
</Context>
tomcat+oracle连接池