Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
999 views
in Technique[技术] by (71.8m points)

java - ORA-01017 when connecting through jdbc thin driver

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!
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...