Runeater DaWizKid
Runeater DaWizKid

Reputation: 81

Issues with username and password when connecting to oracle database 12c through ojdbc

I have SQL developer installed and a properly configured DB, I create a user from sys like so:

CREATE USER random IDENTIFIED BY 12345;
GRANT ALL PRIVILEGES TO random;

I attempt to connect to the oracle SQL database with the ojdbc8.jar found in oracles website like this:

String url = "jdbc:oracle:thin:random/12345@localhost:1521:home";
try{
        Connection dbConn = DriverManager.getConnection(url);
}catch(Exception e){
        System.out.println("Exception: " + e.getLocalizedMessage());
}

However I receive this error:

Exception: ORA-01017: invalid username/password; logon denied

The last time I asked this question it was just populated by answers that have no actual answer to the problem at hand, I don't need to change the driver to a different one, I don't need to instantiate some sort of factory nonsense that just adds complexity, all I want to know is how I'm meant to connect to an account that is part of my DB so I can perform basic SQL functions.

Edit: It just occurred to me that it is a pdb, is there a modification needed to the connection url that anyone can point out?

Upvotes: 0

Views: 495

Answers (2)

Krishnaraj V
Krishnaraj V

Reputation: 27

PDB connections need a slight tweak.

Please use localhost:port/sid instead of localhost:port:sid:

if (isPluggableDB) {
    conn = DriverManager.getConnection("jdbc:oracle:thin:@" + hostName + ":" + hostPort + "/" + sid, userName, password);
} else {
    conn = DriverManager.getConnection("jdbc:oracle:thin:@" + hostName + ":" + hostPort + ":" + sid, userName, password);
}

Upvotes: 0

Neeraj Agarwal
Neeraj Agarwal

Reputation: 1059

Try:

Connection dbConn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:home", "random", "12345");

Upvotes: 1

Related Questions