无法使用服务名称连接到 Oracle 数据库

Unable to connect to Oracle database using Service names

我正在使用以下 LOC 连接到 oracleDB

                    ds.setTNSEntryName(serviceName);
                    ds.setUser(userid);
                    ds.setPassword(password);
                    ds.setDriverType("oci");

                    System.setProperty("oracle.net.tns_admin",oraFilePath);

                    conn = ds.getConnection();  

我在本地机器上使用 JDK 1.8.0_131 和 oracle 12c 12.1.0.1.0。我收到以下版本冲突。

Exception in thread "main" java.lang.Error: Incompatible version of libocijdbc[Jdbc:121020, Jdbc-OCI:121010
        at oracle.jdbc.driver.T2CConnection.run(T2CConnection.java:4126)
        at java.security.AccessController.doPrivileged(Native Method)
        at oracle.jdbc.driver.T2CConnection.loadNativeLibrary(T2CConnection.java:4119)
        at oracle.jdbc.driver.T2CConnection.logon(T2CConnection.java:312)
        at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
        at oracle.jdbc.driver.T2CDriverExtension.getConnection(T2CDriverExtension.java:54)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
        at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:317)
        at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:241)
        at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:184)
        at com.bravura.automation.DatabaseEngine.extractDBdetails(DatabaseEngine.java:67)
        at com.bravura.automation.DatabaseEngine.main(DatabaseEngine.java:41)

POM 文件:

<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.bravura</groupId>
    <artifactId>UTILITIES</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies> 
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.39</version>
    </dependency>  
    <dependency>
        <groupId>com.github.noraui</groupId>
        <artifactId>ojdbc7</artifactId>
        <version>12.1.0.2</version>
    </dependency>

     <dependency>
       <groupId>org.dbunit</groupId>
       <artifactId>dbunit</artifactId>
       <version>2.4.3</version>
     </dependency>

    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.5</version>
   </dependency>
   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
       <version>1.7.5</version>
   </dependency>

    <dependency>
             <groupId>org.apache.poi</groupId>
             <artifactId>poi</artifactId>
             <version>3.14</version>
          </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.14</version>
    </dependency>  
 <dependency>
    <groupId>commons-cli</groupId>
    <artifactId>commons-cli</artifactId>
    <version>1.2</version>
</dependency>

    </dependencies>

    <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>


      </plugin>

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2-beta-4</version>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
       <archive>
         <manifest>
                    <mainClass>com.bravura.automation.DatabaseEngine</mainClass>
            </manifest>
      </archive>
    </configuration>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
     </plugin>
    </plugins>
  </build>

</project>

如何解决 jdbc 和 jdbcoci 之间的版本冲突?我可以通过 POM.xml 控制 JDBC 连接客户端的版本吗?请建议我通过 service_name 连接到 oracle 数据库的任何可能方法。

您需要在数据源上指定 thin 驱动程序:

ds.setDriverType("thin");

oracle.net.tns_adminthin 驱动程序一起使用。 oci 驱动程序需要环境变量 TNS_ADMIN=.