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

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

问题描述

使用




  • 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:无效的用户名/密码;登录被拒绝消息。




  • 我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;

公共类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 =东西)));

String username =myUser;
String password =myPass;

try {
Class.forName(oracle.jdbc.driver.OracleDriver);
连接conn = DriverManager.getConnection(数据库,用户名,密码);
语句stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(select'hello'from dual);
while(rs.next()){
System.out.println(output:+ rs.getString(0));
}
conn.close();
}
catch(例外e){
System.out.println(e.getLocalizedMessage());
}

System.out.println(完成!);
}

}

输出:

  ORA-01017:用户名/密码无效;登录被拒绝

完成!


解决方案

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

 问题描述:
----------- ---------
尝试使用JDBC THIN 11g驱动程序连接到数据库11g
使用企业用户安全性(EUS)连接时抛出无效的用户名/

使用JDBC OCI驱动程序时,可以建立连接。

现在 - 坚持你的帽子:

 可用的解决方法:
----------------------
使用OCI。

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

 测试版本:
----------------
JDBC THIN驱动程序11.1.0.6.0和11.1.0.7.0

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



然后,我们的本地数据库管理员英雄挖了这个:

 通过在命令行上传递选项oracle.jdbc.thinLogonCapability = o3,为JDBC连接设置属性oracle.jdbc.thinLogonCapability = o3。 

例如:
java -Doracle.jdbc.thinLogonCapability = o3< Java Class>

遵循此解决方法时不会失去安全性。

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


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")

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.

  • 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.

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

  • Oracle Client 11.2.0
  • SQLDeveloper Version 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.

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!

解决方案

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.

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. 

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.

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

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