5 Replies Latest reply: Feb 22, 2006 8:47 AM by 486131 RSS

    jdbc. The Network Adapter could not establish the connection. Help Please!!

    485392
      I've found several responses over this issue, but none works for me.

      I'm trying to setup a simple jdbc connection from a simple program.

      Platform:
      Fedora Core 4 (FC4) on AMD 64 bits
      Java 1.4.2_04 (64 bits)
      ORacle 10g or Oracle 9.2.0.4 (none works);

      Tips:
      - I can't connect to a remote server, nor to a local server
      - I can connect using SQLplus
      - TNSPing works fine
      - Listener it's up
      - my connection string is jdbc:oracle:thin:user/name@host:port:sid
      - Also try jdbc:oracle:thin:user/name@//host:port/sid
      - I'v tryied with classes12.jar, odbj14.jar
      - my hostname it's ok.

      I've monitored ip traffic on remote computer. While using TNSPING I detect activity. While using jdbc, no.

      Please, any idea??
        • 1. Re: jdbc. The Network Adapter could not establish the connection. Help Please!!
          Avi Abrami
          user482389,
          Please post the entire error message and stack trace you are getiing, as well as the section of your code where the error is happening.

          I'm sure you're doing something wrong, you just can't see it. Sometimes you just need someone else to look at it and they will find the problem immediately. It's happened to me several times. I've struggled with a problem for hours, and as soon as I asked a colleague to look at my code, they spotted the problem straight away. The opposite has also happened. A colleague asked me to review their code, to find a problem they couldn't resolve, and I found it immediately.

          Are you using the host name, or its IP address? I think you need to use the name. Can you connect remotely with other tools (like Toad, for example)? Are you absolutely certain that your SID and [database connection listener] port are correct?

          Good Luck,
          Avi.
          • 2. Re: jdbc. The Network Adapter could not establish the connection. Help Please!!
            485392
            Thanks for your reply.

            To your questions:
            - I´v tried both IP, host, and even host.domain
            - I can connect from remote workstation using toad, and from local using sqlplus.
            - I can´t connect via jdbc.

            Folowing:
            A) my sample code
            B) the stack trace
            C) the listener status (from my 9i server. Also tryied another servr with 10g)

            when I call this program, I´ve tried severl connection strings:

            jdbc:oracle:thin:user/pass@sdd51:1521:ebf
            jdbc:oracle:thin:user/pass@:sdd51.sdd.com.ar:1521:ebf
            jdbc:oracle:thin:user/pass@:10.10.10.51:1521:ebf

            also try the other sintax:
            jdbc:oracle:thin:user/pass@//sdd51:1521/ebf

            In the classpath, I´tryied:
            clasess12.jar
            ojdbc14.jar
            nls_charset12.jar



            thanks




            A)=================================================
            // Import the JDBC classes
            import java.sql.*;
            import oracle.jdbc.pool.OracleDataSource;

            import java.io.*;
            import java.util.*;

            public class test
            {

            // The query we will execute
            static final String query = "select 'Hello JDBC: ' || sysdate from dual";

            // The connection to the database
            static Connection conn;

            // Create the User Interface
            static public void main (String args[])
            {
            try {
            String connect_string = args[0];
                 // See if we need to open the connection to the database
                 if (conn == null)
                 {
            // Create a OracleDataSource instance and set URL
            OracleDataSource ods = new OracleDataSource();
            ods.setURL(connect_string);

                 // Connect to the databse
                 System.out.println ("Connecting to " + connect_string + "\n");
                 conn = ods.getConnection ();
                 System.out.println ("Connected\n");
                 }

                 // Create a statement
                 Statement stmt = conn.createStatement ();

                 // Execute the query
                 System.out.println ("Executing query " + query + "\n");
                 ResultSet rset = stmt.executeQuery (query);

                 // Dump the result
                 while (rset.next ())
                 System.out.println (rset.getString (1) + "\n");

                 // We're done
                 System.out.println ("done.\n");
            }
            catch (Exception e)
            {
            e.printStackTrace();
                 // Oops
                 System.out.println (e.getMessage () + "\n");
            }
            }
            }


            B)=================================================

            java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
                 at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
                 at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:156)
                 at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
                 at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:212)
                 at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:251)
                 at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:224)
                 at java.sql.DriverManager.getConnection(DriverManager.java:512)
                 at java.sql.DriverManager.getConnection(DriverManager.java:171)
                 at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:102)
                 at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:85)
                 at test.main(test.java:66)


            C)=================================================

            LSNRCTL for Linux: Version 9.2.0.1.0 - Production on 30-JAN-2006 17:39:59

            Copyright (c) 1991, 2002, Oracle Corporation. All rights reserved.

            Connecting to (ADDRESS=(PROTOCOL=tcp)(PORT=1521))
            STATUS of the LISTENER
            ------------------------
            Alias LISTENER
            Version TNSLSNR for Linux: Version 9.2.0.1.0 - Production
            Start Date 24-JAN-2006 11:16:18
            Uptime 6 days 6 hr. 23 min. 40 sec
            Trace Level off
            Security OFF
            SNMP OFF
            Listener Log File /opt/oracle/product/9.2.0/network/log/listener.log
            Listening Endpoints Summary...
            (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=sdd51.sdd.com.ar)(PORT=1521)))
            Services Summary...
            Service "ebf" has 1 instance(s).
            Instance "ebf", status READY, has 1 handler(s) for this service...
            The command completed successfully
            • 3. Re: jdbc. The Network Adapter could not establish the connection. Help Please!!
              Avi Abrami
              user482389,
              I've had problems with the "setURL()" method, too. So I do it this way, instead:
              OracleDataSource ods = new OracleDataSource();
              ods.setDriverType("thin");
              ods.setServerName("sdd51");
              ods.setDatabaseName("ebf");
              ods.setPortNumber(1521);
              ods.setUser("user");
              ods.setPassword("pass");
              conn = ods.getConnection();
              Good Luck,
              Avi.
              • 4. Re: jdbc. The Network Adapter could not establish the connection. Help Please!!
                485392
                Ok, I try this.
                But my real problem is that I´m using another already packaged java aplication, causing the same error. My simple program is a test to isolate problems, excluding aplication server + application issues.

                By the way, when using your sample code, I have the same problem: "The network adapter could not establish connection".

                Do you have other idea about this problem?

                Thanks a lot.
                • 5. Re: jdbc. The Network Adapter could not establish the connection. Help Plea
                  486131
                  i have installed Oracl10g Release 2 in my local system running Windows 2000
                  i'm trying to get connected using JDBC Oracle Thin Driver

                  this is my code
                  -------------------------------------------------------------
                       Class.forName("oracle.jdbc.driver.OracleDriver");
                       con = (oracle.jdbc.OracleConnection) java.sql.DriverManager.getConnection( "jdbc:oracle:thin:@(DESCRIPTION ="+"(ADDRESS = (PROTOCOL = TCP) (HOST = 127.0.0.1)(PORT = 1521))" + "(CONNECT_DATA ="+"(SERVER = DEDICATED)"+ "(SERVICE_NAME = orcl)"+ ")"+ ")","sys/ as sysdba","sys");
                       System.out.println("Connecting to " +con );
                  -----------------------------------------------------
                  error i got:
                  java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

                  stack trace results in :
                  [Ljava.lang.StackTraceElement;@ca0115

                  please. can any body provide a solution??

                  Message was edited by:
                  user483128