1

I'm getting an error while attempting to get a connection to a local(same computer) database "oracle.net.ns.NetException: Got minus one from a read call".

here's the code

    OracleDataSource ods = new OracleDataSource();
    String jdbcURL = "jdbc:oracle:thin:username/userpass@mylinux:1522:sid";
    ods.setURL(jdbcURL);
    Connection conn = ods.getConnection();


Caused by: oracle.net.ns.NetException: Got minus one from a read call
    at oracle.net.ns.Packet.receive(Packet.java:286)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:287)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1054)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:308)
    ... 8 more

What am I missing here ? My brief search on the net didn't turn up anything helpful. I'm linking ojdbc6.jar with the test app.

I can connect just fine from sqlplus using the above credentials.

UPDATE 1 : Am getting the following exception stack trace

Exception in thread "main" java.sql.SQLRecoverableException: IO Error: Got minus one from a read call at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419) at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:536) at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:228) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521) at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280) at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:207) at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:157) at TestOraConn.main(TestOraConn.java:17) Caused by: oracle.net.ns.NetException: Got minus one from a read call at oracle.net.ns.Packet.receive(Packet.java:286) at oracle.net.ns.NSProtocol.connect(NSProtocol.java:287) at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1054) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:308) ... 8 more

UPDATE 2:

lsnrctl status

LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 28-MAY-2013 22:34:16

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 111: Connection refused
anjanb
  • 12,999
  • 18
  • 77
  • 106
  • Are you getting the exception from the `getConnection()` call, or from using that connection later? The whole stack trace would be helpful, as well as the related code with its line numbers. What you have as `sid` needs to be `service name`, but that's true if you're using the same format for SQL*Plus with Easy Connect (or are *only* using the credentials for that?). You can also try [setting the properties individually](http://docs.oracle.com/cd/E11882_01/java.112/e10589/urls.htm#i1058725) rather than with `setURL` to see if that narrows down the problem. – Alex Poole May 28 '13 at 15:51
  • added an update with full stacktrace. getting exception only on the getConnection() call. – anjanb May 28 '13 at 15:57
  • I tried the "setting the properties individually tip. again same result when calling getConnection() on the oracle datasource :-( – anjanb May 28 '13 at 15:59
  • 1
    The connections from sqlplus and the Java program originate from the *same* host? And both use the *same* DNS name (= myhost)? – Beryllium May 28 '13 at 16:07
  • I'm also interested in whether you're hitting the same `mylinux` name/address, or if the SQL*Plus route is using `localhost`, and thus if there's a firewall running that's blocking the access on the external IP address maybe (since other network problems should give a more obvious error, like `connection refused`). You said you were using the same credentials, but are you accessing via SQL*Plus with Easy Connect, or a TNS alias, or something else? I'd try using `localhost` if your listener is, er, listening on that. – Alex Poole May 28 '13 at 16:12
  • @Berylium : sqlplus -- I don't specifically ask for a host. – anjanb May 28 '13 at 16:24
  • @AlexPoole : sqlplus -- I don't specify a host -- I'm assuming that it defaults to localhost. I tried to use "localhost" from my java program. The end result, unforunately, is the same :-( – anjanb May 28 '13 at 16:26
  • @Beryllium : The connections from sqlplus and java program originate on the same machine which runs the oracle server. – anjanb May 28 '13 at 16:28
  • sqlplus command "sqlplus username/userpass" – anjanb May 28 '13 at 16:40
  • OK, so unless you have `TWO_TASK` set, you're connecting locally to `$ORACLE_SID`. You don't necessarily have a listener running, but again I wouldn't expect that error if that is the problem. Check if the listener is up, add the listener.ora and output of `lsnrctl status` to the question. I don't know what it could be except a firewall though. – Alex Poole May 28 '13 at 16:52
  • 1
    I bet that the packets leave the host, and a firewall/stateful packet filter/load balancer whatever *in between* cuts off the connection, that's what is indicated by the -1 from read() – Beryllium May 28 '13 at 17:00
  • stopped iptables firewall : still same result. – anjanb May 28 '13 at 17:01
  • listener.ora : all lines in file commented. – anjanb May 28 '13 at 17:05
  • lsnrctl status ouput : UPDATE2 in the question body. – anjanb May 28 '13 at 17:05
  • So nothing is listening on port 1522? Why did you pick that port in your URL? You need to configure and start the listener before you do anything else. This isn't the right place to ask about that, but follow the docs, and start with `netca`. – Alex Poole May 28 '13 at 17:16
  • @AlexPoole : The DB was installed as part of a script(written by someone else) -- guess something went wrong with the install. I started the listener however, I get the very same error since I assume, it has not been configured correctly. Thanks for helping me so far. – anjanb May 28 '13 at 17:53
  • can you post the content of listener.ora and tnsnames.ora please. I think you have problem in the /etc/hosts. – Ould Abba Jun 23 '13 at 11:03
  • Take a look at this question https://stackoverflow.com/questions/43777075/java-sql-sqlexception-i-o-error-connection-reset-in-linux-server It might help you. – Anderson Bestteti Feb 05 '18 at 17:45

0 Answers0