Forum Stats

  • 3,757,260 Users
  • 2,251,216 Discussions
  • 7,869,781 Comments

Discussions

ORA-01017: invalid username/password; logon denied when connecting Oracle19c db from java program

sonu_gupta(ram)
sonu_gupta(ram) Member Posts: 23 Blue Ribbon
edited May 12, 2021 9:10AM in SQL & PL/SQL

I am able to connect Oracle19 db instance using SQL developer

hostname-localhost

port-1521

servicename- xepdb1

----

I am writing a simple java class - ConnOracle which connects with oracle db and fetch few information.

import java.sql.*;  

class ConnOracle{  

public static void main(String args[]){  

try{  

//step1 load the driver class  

Class.forName("oracle.jdbc.driver.OracleDriver");  

//step2 create the connection object  

Connection con=DriverManager.getConnection(  

"jdbc:oracle:thin:@//localhost:1521/xepdb1","username","MyPassword");

System.out.println(".. created the connection object..");

//step3 create the statement object  

Statement stmt=con.createStatement();    

//step4 execute query  

ResultSet rs=stmt.executeQuery("select * from accounts");  

while(rs.next())  

System.out.println(rs.getInt(1)+" "+rs.getString(2));    

//step5 close the connection object  

con.close();    

}catch(Exception e){ System.out.println(e);}  

  }  

}  


The program is failing at line

Connection con=DriverManager.getConnection(  

"jdbc:oracle:thin:@//localhost:1521/xepdb1","username","MyPassword");

java.sql.SQLException: ORA-01017: invalid username/password; logon denied


what is missing guys , please suggest

«1

Answers

  • Hasitha Amarasiri
    Hasitha Amarasiri Member Posts: 7 Green Ribbon

    Did you upgrade the database to version 19c or any change done from database side? was you able to connect previously or is this the first time?

  • Solomon Yakobson
    Solomon Yakobson Member Posts: 18,722 Black Diamond

    Program is failing - doesn't tell us much. Post error stack.

    SY.

  • Hasitha Amarasiri
    Hasitha Amarasiri Member Posts: 7 Green Ribbon

    Looks like this is due to case sensitive issue can you please use below query to change your database user password with case insensitive password,

    ALTER USER user_name IDENTIFIED BY new_password;
    


  • Solomon Yakobson
    Solomon Yakobson Member Posts: 18,722 Black Diamond

    Password sensitivity has nothing to do with this:

    c:\temp>type test.java
    
    import java.sql.*;
    class DBconnectUsingService
    {
      public static void main (String args [])
           throws SQLException
      {
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        Connection conn =
          DriverManager.getConnection ("jdbc:oracle:thin:@xxx-scan1:1521/pdb1d","UsEr123","PaSs#21");
        System.out.println ("Success.");
      }
    }
    
    c:\temp>cd C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdk\bin
    
    C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdk\bin>set CLASSPATH=C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdbc\lib\ojdbc8.jar;c:\temp
    
    C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdk\bin>javac c:\temp\test.java
    
    C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdk\bin>java DBconnectUsingService
    
    Success.
    
    C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdk\bin>
    

    SY.

  • Hasitha Amarasiri
    Hasitha Amarasiri Member Posts: 7 Green Ribbon

    What did you do?

  • Solomon Yakobson
    Solomon Yakobson Member Posts: 18,722 Black Diamond

    I am surprised (and that's why I asked for error stack) you get invalid username/password since you have two slashes in front of localhost. Look what happens when I put two slashes in front of host name:

    c:\temp>type test.java
    
    import java.sql.*;
    class DBconnectUsingService
    {
      public static void main (String args [])
           throws SQLException
      {
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        Connection conn =
          DriverManager.getConnection ("jdbc:oracle:thin:@//xxx-scan1:1521/pdb1d","UsEr123","PaSs#21");
        System.out.println ("Success.");
      }
    }
    
    c:\temp>cd C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdk\bin
    
    C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdk\bin>set CLASSPATH=C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdbc\lib\ojdbc8.jar;c:\temp
    
    C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdk\bin>javac c:\temp\test.java
    
    C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdk\bin>java DBconnectUsingService
    
    Exception in thread "main" java.sql.SQLRecoverableException: Listener refused the connection with the following error:
    ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
    
    
            at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:774)
            at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:688)
            at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:39)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:691)
            at java.sql.DriverManager.getConnection(DriverManager.java:664)
            at java.sql.DriverManager.getConnection(DriverManager.java:247)
            at DBconnectUsingService.main(test.java:9)
    Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
    ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
    
    
            at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:271)
            at oracle.net.ns.NSProtocol.connect(NSProtocol.java:317)
            at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1438)
            at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:518)
            ... 6 more
    
    C:\app\oracle_home_user\product\19.0.0\dbhome_1\jdk\bin>
    


    SY.

  • Hasitha Amarasiri
    Hasitha Amarasiri Member Posts: 7 Green Ribbon

    Thanks for the update.

  • SureshDooly-Oracle
    SureshDooly-Oracle Member Posts: 35 Employee

    Have you tested the below operations?

    Step 1: alter system set java_jit_enabled=FALSE;

    Step 2: Try your test case. If it is the same issue as ours, your test case will be successful. If it succeeds, Go to step 3. If it does not succeed, it is a different issue.

    Step 3: alter system set java_jit_enabled=TRUE;

    Step 4: Run your test case. If it is the same issue, it is expected to fail. Go to Step 5 in case of failure.

    Step 5: Delete all rows from table java$mc$

    Step 6: Restart the database

    Step 7: Run your test case. It is expected to be successful


    Regards,

    Suresh Umapathy

  • RichardFitz
    RichardFitz Member Posts: 8 Red Ribbon

    The syntax for the jdbc is:  jdbc:oracle:<drivertype>:<username>/<password>@<database>

    In the OP code it shows that the // is after the @.

    Connection con=DriverManager.getConnection(  

    "jdbc:oracle:thin:@//localhost:1521/xepdb1","username","MyPassword");


    You will need to put the // BEFORE the @

    Try that to see if it works.

  • User_H3J7U
    User_H3J7U Member Posts: 460 Bronze Trophy

    java_jit_enabled and java$mc$ belongs to stored procedures, not to client app.