简体   繁体   中英

Invalid username/password while connection oracle 11g through JDBC (110 % Sure that login credentials are correct)

I'm trying to connect to oracle 11g through JDBC, when I'm passing the username and password in the getConnection() method I can connect to the database just fine. But ,when I'm trying to take the input from their user and pass those as arguments.

I'm facing this error

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

I'm using a thin driver and this is how my code looks like:

Connection c=null;
private void getConnection() throws SQLException
{
    System.out.println("Enter login credentials");
    Scanner login=new Scanner(System.in);
    Object Username=login.nextLine();
    Object Password=login.nextLine();
    System.out.println("username"+Username);
    System.out.println("password"+Password);

    c=DriverManager.getConnection("jdbc:oracle:thin:@//localhost:(Omitted wantedly)/XE","Username","Password");
}

I'm able to connect to the database through sql command prompt with same credentials. I've also tried to unlock the user in which I'm in but it didn't help either. Please help !

just replace double quote from username and password.

c=DriverManager.getConnection("jdbc:oracle:thin:@//localhost:(Omitted wantedly)/XE",Username,Password);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM