how to resolve Got minus one from a read call in oracle 11g jdbc 7/14 jdk 1.7?

19,252

Solution 1

DriverManager throws this error when it tries to get a connection with invalid URL. Make sure your URL is valid. Things to checkout:

  1. Port: Oracle db runs on 1521. (note: don't confuse yourself with webport of oracle, which can be any other port as in your URL 1158).
  2. DB name: Get the db name from Oracle Web UI: (home->adminIstration->aboutdatabase->settings)
  3. URL format: "jdbc:oracle:thin:@localhost:1521:YourDbName"

Solution 2

I think the error is in the port number 1158 in this line:

    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1158:ORCL","system", "system");

Normally you connect to an Oracle database using port 1521. Try replacing 1158 with 1521.

Your database may be running the Enterprise Manager on port 1158. That's a web application that you access, often by navigating to https://localhost:1158/em. The Oracle database itself will typically be listening on port 1521.

When using JDBC you need to connect direct to the database, not to some web application instead. The Oracle JDBC driver understands the proprietary binary protocol it uses to communicate with the database, but it doesn't understand the HTTP it gets back from the Enterprise Manager web application. Hence you get an odd network error. You can expect similar random network errors if you attempt to connect the JDBC driver to something else that isn't an Oracle database either.

Share:
19,252
gms
Author by

gms

Updated on June 04, 2022

Comments

  • gms
    gms almost 2 years

    I am using netbeans and jdk 7 updt 9 with 1.7 and following is my code.

    public class jd {
        public static void main(String[] args) throws ClassNotFoundException, SQLException 
    {
            
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1158:ORCL","system", "system");
            System.out.println("Connection successful");
           // Statement s = con.createStatement();
           
        }
        
    }
    

    output is

     run:
        Exception in thread "main" java.sql.SQLRecoverableException: IO Error: Got minus one from a read call
            at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673)
            at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:715)
            at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
            at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564)
            at java.sql.DriverManager.getConnection(DriverManager.java:571)
            at java.sql.DriverManager.getConnection(DriverManager.java:215)
            at jd.main(jd.java:22)
        Caused by: oracle.net.ns.NetException: Got minus one from a read call
            at oracle.net.ns.Packet.receive(Packet.java:314)
            at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:153)
            at oracle.net.ns.NSProtocol.connect(NSProtocol.java:263)
            at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
            at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
            ... 7 more
    
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    
    • Mark Rotteveel
      Mark Rotteveel almost 9 years
      What is the version of the JDBC driver and the version of your server?
    • gms
      gms almost 9 years
      jdbc 6/14.0/14.01/7.0 oracle 11g 11.0.2
  • gms
    gms almost 9 years
    nothing is working, i tried all , its not getting connected using db services , oracle thin , using same setup , mysql connector driver connection is successfull , but oracle sql 11g is not working.
  • gms
    gms almost 9 years
    nothing is working, i tried all , its not getting connected using db services , oracle thin , using same setup , mysql connector driver connection is successfull , but oracle sql 11g is not working.
  • Luke Woodward
    Luke Woodward almost 9 years
    'Nothing is working, I tried all'. Evidently you didn't, as if you did try everything your connection to Oracle would be working by now. So what happened when you changed the port number, as I suggested? What error message did you get? What else have you tried, and what was the outcome in each case (full error messages in each case, please, none of this "it's not working" vagueness). Edit your question to the details of everything you have tried and the results in each case.