JayVeeInCorp
JayVeeInCorp

Reputation: 184

ORA-01017 when connecting through jdbc thin driver

Using

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.

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

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!

Upvotes: 3

Views: 18991

Answers (3)

ThusharaJ
ThusharaJ

Reputation: 419

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

    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"

Upvotes: 0

Jean de Lavarene
Jean de Lavarene

Reputation: 3763

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

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.

Upvotes: 0

JayVeeInCorp
JayVeeInCorp

Reputation: 184

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.

Upvotes: 3

Related Questions