Fix ORA-01017: invalid username/password Error
Overview
Let’s fix ORA-01017: invalid username/password; logon denied error while connecting to Oracle database from JDBC program.
Error trace
Exception in thread “main” java.sql.SQLException: ORA-01017: invalid username/password; logon denied
Fix
Check user credentials
The error is generic and there could multiple causes for the error. First things first, cross check the username and password of the database user credentials.
- Check if username is correct.
- Check if the password is correct.
Connection descriptor
Check the connection descriptor used in the Java program. The database that we try to connect should have the schema specified in the connection descriptor.
For example:
jdbc:oracle:thin:scott/tiger@//localhost:1521/orcl.localdomain
In the above descriptor we are trying to connect to the root CDB container database as SCOTT user. Oracle no longer ships the SCOTT schema with container root starter database.
Thin Service Name Syntax:
“jdbc:oracle:thin:<username>/<password>@//<hostname>:<port>/<servicename>”;
This is most common error where we create the user in pluggable database(PDB). To fix this change the service name in the connection descriptor. For example,
jdbc:oracle:thin:scott/tiger@//localhost:1521/orclpdb.localdomain
We can get the details of the service name in the tnsnames.ora file on the database instance.
Try changes these things and modify the program and try connecting to the database.
That’s it. This should resolve the database connection issue from the Java program.