Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

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

sonu_gupta(ram)May 12 2021 — edited May 12 2021

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

Comments

Post Details

Added on May 12 2021
11 comments
22,940 views