How to Fix ORA-12514 TNS:listener Service Error
Overview
In this post, we will resolve and fix the following Oracle JDBC Thin Driver error. ORA-12514, TNS:listener does not currently know of service requested in connect descriptor.
In this example, we will try to connect to the Oracle database using Oracle JDBC Thin driver. We will connect to pluggable database named orclpdb with SCOTT schema.
Setup schema steps can be found at:
https://www.testingdocs.com/questions/how-to-connect-to-pluggable-database-pdb-using-sqlplus/
Error Trace
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:854)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:793)
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
Cause
Most of the times this error is caused due to malformed service name in the database connection descriptor string used to connect in JDBC program.
Fix
Check if the connection descriptor string:
For example, this is a malformed connection string according to the Oracle Database setup on the machine :
“jdbc:oracle:thin:scott/tiger@localhost:1521/orcl”
The connection descriptor string should be formed using the tnsnames.ora file from the database instance that we are trying to establish the connection. The exact hostname, port, and the service name can be found in the tnsnames.ora file.
On Windows the file can be found at the following path: %ORACLE_HOME%\network\admin
1 -> Host name
2 -> Port
3 -> Service Name, here in this case the pluggable database.
JDBC Thin Service name Syntax
The correct format is:
“jdbc:oracle:thin:<username>/<password>@//<hostname>:<port>/<servicename>”;
So the correct connection descriptor string is:
“jdbc:oracle:thin:scott/tiger@//localhost:1521/orclpdb.localdomain”
—
Oracle Database Tutorials on this website:
https://www.testingdocs.com/oracle-database-tutorials-for-beginners/
More information about Oracle Database: