简体   繁体   中英

Configure DBCP based connection pool for interacting with oracle db

I am trying to run this example http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/doc/PoolingDataSourceExample.java?view=markup but somehow I am not able to do it. And I want to run this example in an maven project and also I am working on the maven project for the first time. And I am not sure how should I do it. As in that example it clearly states that-

To compile this example, you'll want:
  * commons-pool-1.5.4.jar
  * commons-dbcp-1.2.2.jar
  * j2ee.jar (for the javax.sql classes)
 in your classpath.

 To run this example, you'll want:
  * commons-pool-1.5.6.jar
  * commons-dbcp-1.3.jar (JDK 1.4-1.5) or commons-dbcp-1.4 (JDK 1.6+)
  * j2ee.jar (for the javax.sql classes)
  * the classes for your (underlying) JDBC driver
 in your classpath.

So I tried adding all these dependencies into my pom.xml file after going through various articles. But still I am having error like--

ConnectionFactory cannot be resolved to a type  
GenericObjectPool cannot be resolved to a type  
ObjectPool cannot be resolved to a type 
PoolableConnectionFactory cannot be resolved to a type  
PoolableConnectionFactory cannot be resolved to a type  
PoolingDataSource cannot be resolved to a type  
PoolingDataSource cannot be resolved to a type  

And this is my pom.xml file. Is there anything that I am missing in my pom.xml file. Any suggestions will be appreciated as this is my first time with maven project.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.datasource.pooling</groupId>
  <artifactId>datasource.pooling</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>com.datasource.pooling</name>




  <dependencies>

  <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0</version>
        </dependency>


<dependency>
      <groupId>commons-pool</groupId>
      <artifactId>commons-pool</artifactId>
      <version>1.5.4</version>
    </dependency>

    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.2.2</version>
    </dependency>
<!--  
<dependency>
      <groupId>commons-pool</groupId>
      <artifactId>commons-pool</artifactId>
      <version>1.5.6</version>
    </dependency>

    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.3</version>
    </dependency>
 -->

  </dependencies>
</project>

What is the dependency for adding j2ee.jar file.

ConnectionFactory, GenericObjectPool,ObjectPool,PoolableConnectionFactory,PoolingDataSource classes can be found in jars commons-pool-{version}.jar and commons-dbcp-{version}.jar.

In this case, you don't have to add j2ee.jar. javax.sql package related classes are inside rt.jar which comes default in . The code ( http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/doc/PoolingDataSourceExample.java?view=markup ) you have to run is importing classes from package org.apache.commons.dbcp2 and org.apache.commons.pool2

import org.apache.commons.pool2.ObjectPool; 
import org.apache.commons.pool2.impl.GenericObjectPool;      
import org.apache.commons.dbcp2.ConnectionFactory;   
import org.apache.commons.dbcp2.PoolingDataSource;   
import org.apache.commons.dbcp2.PoolableConnectionFactory;   
import org.apache.commons.dbcp2.DriverManagerConnectionFactory;

instead use

import org.apache.commons.pool.ObjectPool; 
import org.apache.commons.pool.impl.GenericObjectPool;   
import org.apache.commons.dbcp.ConnectionFactory;    
import org.apache.commons.dbcp.PoolingDataSource;    
import org.apache.commons.dbcp.PoolableConnectionFactory;    
import org.apache.commons.dbcp.DriverManagerConnectionFactory;

use org.apache.commons.pool instead of org.apache.commons.pool2 from all the package imports. These classes are inside commons-pool-{version}.jar and commons-dbcp-{version}.jar jars.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM