CodexBloom - Programming Q&A Platform

OCI Database: ORA-12541 scenarios Occurring When Connecting from Java Application

👀 Views: 90 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-09
oci oracle jdbc java database Java

I'm migrating some code and I'm experiencing an `ORA-12541: TNS:no listener` behavior when trying to connect to my Oracle Cloud Infrastructure (OCI) database from a Java application using JDBC. I have confirmed that the database is running, and I can connect to it using SQL Developer without any issues. However, when I run my Java application, it fails with the following stack trace: ``` Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following behavior: ORA-12541: TNS:no listener at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:853) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:615) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:451) ... ``` Here's the JDBC connection string I'm using: ```java String jdbcUrl = "jdbc:oracle:thin:@//<DB_PUBLIC_IP>:1522/<DB_SERVICE_NAME>"; ``` I have verified that the public IP is correct and that I can ping the IP from my machine. The database service name seems to be accurate as well. Additionally, I have opened port 1522 in the Security Lists for my database subnet. I also tried using the `tnsnames.ora` configuration instead, but that didn't resolve the connection scenario either. My OCI database version is 19c, and I am using the Oracle JDBC driver version 19.8.0.0.0. I've checked the listener status on the database instances using: ```bash lsnrctl status ``` The listener shows that it is up and running. I am unsure if this scenario might be related to Oracle's network security rules or the way my JDBC URL is constructed. Any guidance on how to troubleshoot this further or potential misconfigurations would be greatly appreciated! I'd really appreciate any guidance on this.