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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28945312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:28:15  来源:igfitidea点击:

ORA-01017 when connecting through jdbc thin driver

javaeclipsejdbcoracle11g

提问by JayVeeInCorp

Using

使用

  • the Oracle Database 11g Release 2 (11.2.0.4) JDBC Driver "ojdbc6.jar" (from this page),
  • Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production (verified by doing "select * from v$version")
  • Oracle 数据库 11g 第 2 版 (11.2.0.4) JDBC 驱动程序“ojdbc6.jar”(来自本页),
  • Oracle 数据库 11g 企业版 11.2.0.4.0 版 - 64 位生产(通过执行“select * from v$version”验证)

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.

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

  • I'm 100% certain that the username and password I'm inputting in my code is correct. I have verified this by going as far as copy-pasting the values from my code in the connection manager of SQLDeveloper, where connecting works fine.
  • The ojdbc6.jar-file is imported in my Eclipse project (as a library).
  • The TNS string is copied from a tnsping to the TNS name which works in SQLDeveloper.
  • I've additionally verified that the username / password for the server I'm using are not case sensitive (by connecting in SQL developer using an uppercased version of my username and password, and trying the same with a lowercased version), as there was some issue with that on earlier JDBC drivers.
  • 我 100% 确定我在代码中输入的用户名和密码是正确的。我已经通过在 SQLDeveloper 的连接管理器中复制粘贴我的代码中的值来验证这一点,连接工作正常。
  • ojdbc6.jar 文件被导入到我的 Eclipse 项目中(作为一个库)。
  • TNS 字符串从 tnsping 复制到在 SQLDeveloper 中工作的 TNS 名称。
  • 我还验证了我正在使用的服务器的用户名/密码不区分大小写(通过使用我的用户名和密码的大写版本在 SQL 开发人员中连接,并尝试使用小写版本相同),因为有早期 JDBC 驱动程序上的一些问题。

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

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

  • Oracle Client 11.2.0
  • SQLDeveloper Version 4.0.1.14
  • 甲骨文客户端 11.2.0
  • SQLDeveloper 版本 4.0.1.14

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.

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

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!");
    }

}

Output:

输出:

ORA-01017: invalid username/password; logon denied

Done!

采纳答案by JayVeeInCorp

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

一位友好的 DB 管理员出手相救,发现这实际上是一个 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.

And now - hold on to your hats:

现在 - 抓住你的帽子:

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

Note that I used 11.2.0.4, while the bug says

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

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. 

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.

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

回答by Jean de Lavarene

EUS (Entreprise Users) are supported in the JDBC-thin driver starting in 11.2.0.3 but did you verify that indeed the user "myUser" is defined as an EUS in the database? EUS users are defined in a central directory (OID for example) and are not normal user you create in the database by doing "create user".

从 11.2.0.3 开始,JDBC-thin 驱动程序支持 EUS(企业用户),但您是否确认用户“myUser”确实被定义为数据库中的 EUS?EUS 用户定义在中央目录(例如 OID)中,并且不是您通过执行“创建用户”在数据库中创建的普通用户。

One additional note: SQLDeveloper uses the JDBC thin driver. So if you can connect with SQLDeveloper then you should also be able to connect from your standalone JDBC program. Just make sure SQLDeveloper uses the same jdbc jar as the one you're using. If you want to check the version of the JDBC driver that you're using just do "java -jar ojdbc7.jar" which will print the version.

附加说明:SQLDeveloper 使用 JDBC 瘦驱动程序。因此,如果您可以与 SQLDeveloper 连接,那么您也应该能够从独立的 JDBC 程序进行连接。只要确保 SQLDeveloper 使用与您正在使用的相同的 jdbc jar。如果您想检查您使用的 JDBC 驱动程序的版本,只需执行“java -jar ojdbc7.jar”即可打印版本。

回答by ThusharaJ

Similar exception can occur if username and password is specified (even empty values) in oracle thin walletconnection configurations. Below configurations would work.

如果在 oracle 瘦钱包连接配置中指定了用户名和密码(甚至是空值),则会发生类似的异常。以下配置将起作用。

    System.setProperty("oracle.net.wallet_location", [wallet location]);
    System.setProperty("oracle.net.tns_admin", [Tns location]);

    "url" =  "jdbc:oracle:thin:/@tns_alias"
    "driver_class" =  "oracle.jdbc.driver.OracleDriver"