tomcat 连接oracle

 在tomcat 6.0.中配置数据源连接Oracle数据库的方法



拷贝数据库驱动包.到apache-tomcat-6.0.29\lib目录下:

我这里以oracle10G为例.需要拷贝:ojdbc14.jar.

 

2.打开apache-tomcat-6.0.29\conf目录中的content.xml文件.

在此文件中配置Resource

 
Xml代码
<?xml version='1.0' encoding='utf-8'?>
<Context>
    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    
    <!--数据源-->  
  <Resource
        name="jdbc/DBSource"          <!--数据源名称,格式通常为jdbc/xxx名称-->
           type="javax.sql.DataSource"  <!--数据源类型-->
           username="scott"                   <!--连接数据库用户名-->
           password="tiger"                    <!--连接数据库密码-->
           maxIdle="2"                            <!--最大空闲数,数据库连接的最大空闲时间。超过空闲时间,数据库连接将被标记为不可用,然后被释放。设为0表示无限制。-->
           maxWait="5000"                     <!--最大的等待时间,单位毫秒。如果超过此时间将接到异常。设为-1表示无限制-->
           url="jdbc:oracle:thin:@localhost:1521:orcl"     
           driverClassName="oracle.jdbc.driver.OracleDriver"
           maxactive="10"                 <!--连接池的最大数据库连接数。设为0表示无限制-->
    />
</Context>

3.在Web项目中的web.xml里面需要引用数据源:

<!-- 引用数据源; -->
  <resource-ref>
   <description>Oracle dataSource</description>
   <res-ref-name>jdbc/DBSource</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Shareable</res-sharing-scope>
  </resource-ref>

posted on 2018-01-22 08:55  一去二三里  阅读(1717)  评论(0编辑  收藏  举报

导航