1

What i've tried so far: -Pinging to the server from another server. It was successful -Made the the database and listener is up and running on port 1521

One thing I am confused about is no example code whatsoever makes any mention about including the password for the server itself. They only mention about the database password. Also I doubt than im suppose to download the Oracle Software on this computer(client), but please let me know if i'm wrong.

Here's my code. Btw im using a 12c database

  import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;

public class OracleTest {

    public static void main(String[] args) {


        System.out.println("-------- Oracle JDBC Connection Testing ------");

        try {

            Class.forName("oracle.jdbc.driver.OracleDriver");

        } catch (ClassNotFoundException e) {

            System.out.println("Where is your Oracle JDBC Driver?");
            e.printStackTrace();
            return;

        }

        System.out.println("Oracle JDBC Driver Registered!");

        Connection connection = null;

        try {

            connection = DriverManager.getConnection(
                    "jdbc:oracle:thin:@11.111.1.1:1521:SID", "schema", "password");

        } catch (SQLException e) {

            System.out.println("Connection Failed! Check output console");
            e.printStackTrace();
            return;

        }

        if (connection != null) {
            System.out.println("You made it, take control your database now!");
        } else {
            System.out.println("Failed to make connection!");
        }
    }

}

Here is the exact Errors:

-------- Oracle JDBC Connection Testing ------
Oracle JDBC Driver Registered!
Connection Failed! Check output console
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743)
    at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at OracleTest.main(OracleTest.java:30)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:470)
    at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:506)
    at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:595)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:230)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1452)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:496)
    ... 6 more
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:161)
    at oracle.net.nt.ConnOption.connect(ConnOption.java:159)
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:428)
    ... 11 more
  • 2
    instead of www.hostname.com - put in the network name of the server, or its IP address. You don't login to a database via a server os user/pwd - but just using your db user/password – thatjeffsmith Sep 10 '17 at 14:19
  • I've never worked with Oracle DB from Java, but my guess is your connection URL has a problem somewhere. Have a look at this SO question: https://stackoverflow.com/questions/1054105/url-string-format-for-connecting-to-oracle-database-with-jdbc – Tim Biegeleisen Sep 10 '17 at 14:20
  • did you run TNSPING ? – OldProgrammer Sep 10 '17 at 14:24
  • @OldProgrammer On the host server yes. Am I supposed to tnsping from the client server? And to do that, would I have to download the oracle software? – Linux Oracle User Sep 10 '17 at 14:26
  • you JUST need an Oracle JDBC driverhttp://www.oracle.com/technetwork/database/features/jdbc/jdbc-drivers-12c-download-1958347.html you can do a simple OS ping to see if you can reach the db server on the network. the oracle client includes a utility called TNSPing which will see if the db service you want to connect to can be resolved – thatjeffsmith Sep 10 '17 at 14:32
  • @thatjeffsmith I can ping to the server of the database just fine. tnsping also returns successful while on the database server. My local computer doesn't have the oracle software, so im assuming im not suppose to tnsping from it? – Linux Oracle User Sep 10 '17 at 14:39
  • from your machine where your java program is running, you need, a JDBC driver, network access to the server, and the database listener port (1521) needs to be open. And you need a valid username/password. Did you see my comment on your URL? – thatjeffsmith Sep 10 '17 at 14:44
  • @thatjeffsmith Yes, I have all of that. I just didn't include the actual username/password on my post but I do have it in my code. – Linux Oracle User Sep 10 '17 at 14:49
  • what's the EXACT error message you receive when you attempt a connection? also, replace www.hostname.com with the server IP address and try again – thatjeffsmith Sep 10 '17 at 14:54
  • @thatjeffsmith Added to the OP. – Linux Oracle User Sep 10 '17 at 15:03
  • It's 12c - replace the SID with the db SERVICE name – thatjeffsmith Sep 10 '17 at 15:03
  • @thatjeffsmith they are identical. And I doubt you mean the actual tnsnames connect string, – Linux Oracle User Sep 10 '17 at 15:20
  • @thatjeffsmith Ok so i realized this may be some sys admin related issue. I was able to connect to an ec2 instance successfully. Not sure why the other server didn't connect. – Linux Oracle User Sep 10 '17 at 16:00
  • mostly likely firewall blocking your ip/domain or the port isn't open – thatjeffsmith Sep 10 '17 at 16:01

0 Answers0