Fix ORA-12514 TNS:listener Service Error
Fix ORA-12514 TNS: listener Service Error
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 the Oracle JDBC Thin driver. We will connect to a pluggable database named orclpdb with the SCOTT schema.
Setup schema steps can be found at:
Error Trace
java.sql.SQLRecoverableException: Listener refused the connection with the following error:
ORA-12514, TNS: listener does not currently know of the service requested in the 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
A malformed service name usually causes this error in the database connection descriptor string used to connect in the 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 we are trying to establish the connection. The exact hostname, port, and service name are in the tnsnames.ora file.
On Windows, the file can be found at the following path:
%ORACLE_HOME%\network\admin
- 1 -> Hostname
- 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”