说明
在 springboot 中,使用 odbc 连接 Oracle 数据库的时候,出现了下面的错误:
java.sql.SQLException: ORA-01005: null password given; logon denied
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:702) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:603) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:598) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1710) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:819) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:1041) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:443) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:462) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTHWithO5Logon(T4CTTIoauthenticate.java:1628) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:1375) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:1322) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CConnection.authenticateWithPassword(T4CConnection.java:1500) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CConnection.authenticateUserForLogon(T4CConnection.java:1443) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:812) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:1101) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:104) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:837) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:664) ~[ojdbc8-23.2.0.0.jar!/:23.2.0.0.0]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) [HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) [HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) [HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) [HikariCP-4.0.3.jar!/:na]
主要提示信息为:java.sql.SQLException: ORA-01005: null password given; logon denied,但是实际上,在有的机器上是正常运行的,但是有的机器运行提示该错误。
后来查看相关资料以及尝试后,发现,不同的 JDK 版本,对 ORACLE 的数据源依赖的版本有要求。
此处,运行正常的 JDK 版本:JDK1.8.0_361
运行不正常的 JDK 版本:JDK1.8.0_121。
解决方案
将 oracle 驱动更换成低版本,如下面的版本:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>