如何配置TOMCAT+ORACLE连接池?

可以通过配置DBCP连接池,在Server.xml中加入 
  <Context  path="/demo"  docBase="D:/demo"> 
                  <Resource  name="jdbc/demo"  scope="Shareable"  type="javax.sql.DataSource"/> 
                  <ResourceParams  name="jdbc/demo"> 
                          <parameter> 
                                  <name>factory</name> 
                                  <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> 
                          </parameter> 
           
                          <!--  DBCP  database  connection  settings  --> 
                          <parameter> 
                                  <name>url</name> 
                                  <value>jdbc:oracle:thin:@10.0.0.10:1521:demo</value> 
                          </parameter> 
                          <parameter> 
                                  <name>driverClassName</name> 
                                  <value>oracle.jdbc.driver.OracleDriver</value> 
                          </parameter> 
                          <parameter> 
                                  <name>username</name> 
                                  <value>demo</value> 
                          </parameter> 
                          <parameter> 
                                  <name>password</name> 
                                  <value>demo</value> 
                          </parameter> 
           
                          <!--  DBCP  connection  pooling  options  --> 
                          <parameter> 
                                  <name>maxWait</name> 
                                  <value>3000</value> 
                          </parameter> 
                          <parameter> 
                                  <name>maxIdle</name> 
                                  <value>100</value> 
                          </parameter> 
                          <parameter> 
                                  <name>maxActive</name> 
                                  <value>10</value> 
                          </parameter> 
                  </ResourceParams> 
          </Context>
一样,是配置web服务器,在你用得到的时候取出来就行了 
              InitialContext  initContext  =  new  InitialContext(); 
              String  dsName  =  "java:comp/env/jdbc/demo"; 
              DataSource  ds  =  null; 
              try  { 
                  ds  =  (DataSource)  initContext.lookup(dsName); 
              } 
              catch  (NameNotFoundException  nfex)  { 
                  dsName  =  "jdbc/demo"; 
                  ds  =  (DataSource)  initContext.lookup(dsName); 
              } 
              if  (ds  !=  null)  { 
                  con  =  ds.getConnection(); 
              }

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值