This discussion is archived
7 Replies Latest reply: Dec 10, 2012 1:49 PM by dsurber RSS

Java error while connecting to DB

Phelit Newbie
Currently Being Moderated
I have a Java application that works on a DB with Oracle 10g. The server is a Windows Server 2003 R2 SP2. This application every now and then, for no apparent reason, stops working for a few seconds and then starts working again. I did a few tests and ended up in creating a small procedure that connects and disconnects to the DB about 1000 times in a row. The application works perfectly, the time of response is great but at a certain point, when I launched this procedure a few times I start getting this error about 60 times and the connection to the DB becomes blocked for a few seconds and then it goes back to normal:

java.sql.SQLException: Io exception: The Network Adapter could not establish theconnection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:439)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Test.connetti(Test.java:42)
at Test.main(Test.java:25)
0



I believe I might have hit the spot....but I have no idea why I get this error! It is quite annoying since it happends for an application that a lot of users need to use!

Any help?
Thanks!

P.s. I get the error both from remote and from the local host, so it appears it is not a networking problem.
  • 1. Re: Java error while connecting to DB
    gimbal2 Guru
    Currently Being Moderated
    Windows has a limit on the amount of network connections that can be created within a certain timeframe (a second, I believe). Might be that you are hitting that limit.
  • 2. Re: Java error while connecting to DB
    Phelit Newbie
    Currently Being Moderated
    I thought about it, but the same thing doesn't happend for another DB on the same machine! So I don't think is that! Thanks
  • 3. Re: Java error while connecting to DB
    gimbal2 Guru
    Currently Being Moderated
    In any case the exception indicates some sort of connection failure. Might be a problem of system resources (handles), might be anything. You can't debug problems like this by staring at code in any case. Perhaps database logs can give some clue as to why connections are failing, although if the server is involved I would expect exceptions of the 'rejected' or 'reset by peer' variant.
  • 4. Re: Java error while connecting to DB
    EJP Guru
    Currently Being Moderated
    Once again I will state that this idiotic message needs to be removed and replaced by the actual text of the IOException that caused it, so that people like this poster could see what the actual problem is. Network adapters in the form of NICs do not establish connections: TCP/IP protocol stacks do; and if 'network adapter' refers to a software component inside Oracle's JDBC code it is of no interest to outsiders. Unlike the IOException text ('connection refused', 'connection timed out', 'no route to host', etc).

    @JoeWeinstein please note.
  • 5. Re: Java error while connecting to DB
    dsurber Explorer
    Currently Being Moderated
    I just looked at the code and the only place that message is used the constructed exception has the original exception set as the cause. So the underlying cause is available to the user. There could have been multiple exceptions in which case only the last is given as the cause. The code also handles the case where the failure isn't caused by an exception, hence no cause, though it's not obvious how that could actually happen.

    Douglas
  • 6. Re: Java error while connecting to DB
    EJP Guru
    Currently Being Moderated
    Very good, thanks for looking, but the fact remains that the error message is meaningless, or should I say content-free, and indeed misleading. A quick search of this forum will show many stack traces with this message where the underlying exception never appeared at all, and where to all appearances the poster never resolved the problem, simply as a consequence of this poor design. It will also reveal several prior instances of my rant.

    @OP please post the full stack trace including all nested exceptions.
  • 7. Re: Java error while connecting to DB
    dsurber Explorer
    Currently Being Moderated
    Can you suggest better wording for the message?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points