gpt4 book ai didi

java - 通过 jdbc 瘦驱动程序连接时出现 ORA-01017

转载 作者:行者123 更新时间:2023-11-30 08:55:32 25 4
gpt4 key购买 nike

使用

  • Oracle 数据库 11g 第 2 版 (11.2.0.4) JDBC 驱动程序“ojdbc6.jar”(来自 this page),
  • Oracle 数据库 11g 企业版 11.2.0.4.0 版 - 64 位生产(通过执行“select * from v$version”验证)

我正在尝试使用 JDBC 驱动程序从 Java 应用程序连接到数据库。这将失败并显示“ORA-01017:无效的用户名/密码;登录被拒绝”消息。

  • 我 100% 确定我在代码中输入的用户名和密码是正确的。我已经通过在 SQLDeveloper 的连接管理器中复制粘贴我的代码中的值来验证这一点,连接工作正常。
  • ojdbc6.jar 文件已导入到我的 Eclipse 项目中(作为库)。
  • TNS 字符串从 tnsping 复制到在 SQLDeveloper 中工作的 TNS 名称。
  • 我还验证了我正在使用的服务器的用户名/密码不区分大小写(通过使用我的用户名和密码的大写版本在 SQL 开发人员中连接,并尝试使用小写版本),因为在早期的 JDBC 驱动程序上存在一些问题。

我电脑上安装的东西(我无能为力):

  • Oracle 客户端 11.2.0
  • SQLDeveloper 版本 4.0.1.14

我不认为这些是干扰,因为从 Eclipse 项目使用的库中删除 ojdbc6.jar 不会产生任何输出(没有错误,也没有来自 select 子句的输出),所以我很确定实际上正在使用瘦驱动程序。

我创建了一个小型测试应用程序来演示该问题:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class OracleTester {

public static void main(String[] args) {
String database = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xx.xxx.xxx)(PORT=13301)))(CONNECT_DATA=(SERVICE_NAME=something)))";

String username = "myUser";
String password = "myPass";

try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(database,username,password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select 'hello' from dual");
while(rs.next()){
System.out.println("output: " + rs.getString(0));
}
conn.close();
}
catch(Exception e){
System.out.println(e.getLocalizedMessage());
}

System.out.println("Done!");
}

}

输出:

ORA-01017: invalid username/password; logon denied

Done!

最佳答案

一位友好的数据库管理员前来救援,发现这实际上是一个 Oracle 错误:

Problem Description:
--------------------
When trying to connect by using the JDBC THIN 11g driver to a database 11g
using Enterprise User Security (EUS) connections throw invalid username/

When usign the JDBC OCI driver the connection can be made.

现在 - 捕获你的帽子:

Available Workarounds:
----------------------
Use OCI.

请注意,我使用的是 11.2.0.4,而错误说

Tested Versions:
----------------
JDBC THIN Driver 11.1.0.6.0 and 11.1.0.7.0

显然它已经存在了一段时间。我不确定我是否理解 - 如果无法正确连接到数据库,他们为什么要推出该驱动程序的新版本?这似乎是每个人在使用瘦驱动程序时遇到的第一个问题?

但是,我们本地的数据库管理员英雄挖出了这个:

Set the property oracle.jdbc.thinLogonCapability=o3 for the JDBC connection by passing the option oracle.jdbc.thinLogonCapability=o3 on the command line.  

For example:
java -Doracle.jdbc.thinLogonCapability=o3 <Java Class>

There is no loss of security when following this workaround.

在 Eclipse 中,我已将此行添加到 VM 参数(运行 -> 运行配置 -> 参数 -> VM 参数 -> 添加 -Doracle.jdbc.thinLogonCapability=o3),你看,我终于可以进入数据库。

关于java - 通过 jdbc 瘦驱动程序连接时出现 ORA-01017,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28945312/

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