通过 jdbc 瘦驱动程序连接时出现 ORA-01017 [英] ORA-01017 when connecting through jdbc thin driver

查看:26
本文介绍了通过 jdbc 瘦驱动程序连接时出现 ORA-01017的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

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

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

I'm trying to connect to the database from a Java application using the JDBC Driver. This fails with a "ORA-01017: invalid username/password; logon denied" message.

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

我的电脑上安装的东西(我没有权力):

Things installed on my computer (over which I have no power):

  • Oracle 客户端 11.2.0
  • SQLDeveloper 版本 4.0.1.14

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

I don't think these are interfering, as removing the ojdbc6.jar from the libraries the Eclipse project uses gives rise to no output (no errors, also no output from the select-clause), so I'm fairly sure the thin driver is in fact being used.

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

I've created a small test application to demonstrate the problem:

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!

推荐答案

一位友好的 DB admin 前来救援,发现这其实是一个 Oracle 的 bug:

A friendly DB admin came to the rescue, and found that this is actually an Oracle bug:

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.

现在 - 抓住你的帽子:

And now - hold on to your hats:

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

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

Note that I used 11.2.0.4, while the bug says

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

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

So apparently it's been around for a while. I'm not sure I get this - why are they bringing out new versions of this driver if it fails on connecting you to the database properly? Seems this would be the first issue everybody runs into when using the thin driver?

但是,我们本地的数据库管理员英雄发现了这一点:

But then, our local DB admin hero dug this up:

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),瞧,我终于可以进入数据库.

In Eclipse, I've added this line to the VM arguments (Run -> Run Configurations -> Arguments -> VM arguments -> add -Doracle.jdbc.thinLogonCapability=o3) and, lo and behold, I can finally get into the database.

这篇关于通过 jdbc 瘦驱动程序连接时出现 ORA-01017的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆