我使用以下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$1.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数据库的任何可能方法。
答案 0 :(得分:2)
您需要在数据源上指定thin
驱动程序:
ds.setDriverType("thin");
答案 1 :(得分:-1)
oracle.net.tns_admin
与thin
驱动程序一起使用。
oci
驱动程序需要环境变量TNS_ADMIN=
。