gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 12:01:30 26 4
gpt4 key购买 nike

我使用以下 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数据库的任何可能的方式。

最佳答案

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

ds.setDriverType("thin");

关于java - 无法使用服务名称连接到 Oracle 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47220981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com