6 Replies Latest reply on Jan 2, 2012 1:49 PM by xploreraj

    JDBC Connection not established for a simple program!    HOW TO?

    xploreraj

      Hi, I have written a first JDBC program after successfully installing Oracle . I am able to use SQL Plus prompt for creating and manipulating tables.

      The connection is not establishing. You can view the error image at this link:
      [Click to see Error Image|http://img833.imageshack.us/img833/880/errorjdbc2.png] or
      http://img833.imageshack.us/img833/880/errorjdbc2.png

      Please refer to my program below:

      -------------------------------------------------------------------------

      /**
      JDK : 1.6.0_18
      Oracle : 11G (11.1.0.7.0)
      Remarks : Driver is loaded, but connection is not established. Tables can be created and modified with SQL Plus.
      SYSTEM VARIABLES:-

      CLASSPATH : .;%ORACLE_HOME%\jdbc\lib\ojdbc6.jar;%ORACLE_HOME%\oui\jlib\classes12.jar;C:\jdk1.6.0_18\jre\lib\ext\mysql-connector-java-5.0.4-bin.jar;C:\jdk1.6.0_18\lib\tools.jar;C:jdk1.6.0_18\jre\lib\rt.jar;

      PATH : C:\jdk1.6.0_18\bin;%ORACLE_HOME%\bin;C:\PROGRAM FILES\MYSQL\MYSQL SERVER 5.0\BIN;C:\PROGRAM FILES\COMMON FILES\MICROSOFT SHARED\WINDOWS LIVE;%SYSTEMROOT%\SYSTEM32;%SYSTEMROOT%;%SYSTEMROOT%\SYSTEM32\WBEM;%SYSTEMROOT%\SYSTEM32\WINDOWSPOWERSHELL\V1.0\;C:\PROGRAM FILES\WINDOWS LIVE\SHARED;

      in tnsnames.ora file: port_no=1521; service_name=orcl
      */


      import java.sql.*;

      class FirstProgram
      {
      public static void main(String[] args) throws ClassNotFoundException, SQLException
      {
      Class.forName("oracle.jdbc.driver.OracleDriver");
      System.out.println("Driver loaded"); //indicates driver registration
      String cs="jdbc:oracle:thin:@localhost:1521:orcl";

      Connection con=DriverManager.getConnection(cs,"scott","tiger");
      System.out.println("Connected");
      //not printing; no connectivity

      con.close();
      }
      }

      ---------------------------------------------------------

      Your help is appreciated. Thanks.

      Edited by: xploreraj on Dec 31, 2011 10:54 AM

        • 1. Re: JDBC Connection not established for a simple program!    HOW TO?
          DrClap
          Just tell us what the error message says. Don't make us download things from sites which we don't know are safe. You do know how to do copy-and-paste, don't you?
          • 2. Re: JDBC Connection not established for a simple program!    HOW TO?
            xploreraj
            Oops, I respect your concern. The link is for an image.

            I am posting the error message for your concern:


            Driver loaded
            Exception in thread "main" java.sql.SQLException: Got minus one from a read call
            at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
            at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:480)
            at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:413)
            at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:508)
            at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)
            at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at FirstProgram.main(FirstProgram.java:17)
            Caused by: oracle.net.ns.NetException: Got minus one from a read call
            at oracle.net.ns.Packet.receive(Packet.java:243)
            at oracle.net.ns.NSProtocol.connect(NSProtocol.java:259)
            at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:966)
            at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:292)
            ... 7 more


            =================

            I have also noticed that Apache Tomcat 5 which was running fine on port number 8080 was also not working. Even after multiple tries, the service won't start up.
            So I think that's some port problem.

            Please help.

            Thanks
            • 3. Re: JDBC Connection not established for a simple program!    HOW TO?
              EJP
              I would say that whatever is listening on the port you specified isn't an Oracle DBMS server.

              It's curious that you also have MySQL in your CLASSPATH.
              • 4. Re: JDBC Connection not established for a simple program!    HOW TO?
                xploreraj
                So, how to resolve the issue. Specifically I feel that ports are not opening up or have been jammed. some system settings to do ? also apache tomcat not working. port 8080. was working few days back.
                os-win 7 32bit

                thanks
                • 5. Re: JDBC Connection not established for a simple program!    HOW TO?
                  EJP
                  Err, make sure you're citing the correct ports, make sure they are open in your Windows firewall, and get rid of the MySQL elements in your CLASSPATH? Surely that's obvious?

                  And note that only the last has anything whatsoever to do with Java.
                  • 6. Re: JDBC Connection not established for a simple program!    HOW TO?
                    xploreraj
                    okay, modified the classpath. i will check the windows firewall thing and report..thanks EJP