File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Broken Pipe exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Broken Pipe exception" Watch "Broken Pipe exception" New topic
Author

Broken Pipe exception

Shraga van Shufel
Ranch Hand

Joined: Apr 20, 2003
Posts: 33
Hello,

In my struts application I define a data source to an Oracle DB, everything works as it should until there is a communication problem between the application and the DB (broken pip etc�.)
When this problem occurred the application encounter several exceptions and the only way to bring it back to working status is restarting it.

When I we used MySQL database we could specify the autoreconnect parameter (i.e jdbc:mysql://MyDBhost/myDB?autoReconnect=true)

However I could not add this parameter to the Oracle connection string.

Is it possible to add a similar flag in the Oracle url, if not what is good approach for initializing the pool once we encounter network problems.

Thanks in advance

/Shraga.
sarah Marsh
Ranch Hand

Joined: Mar 06, 2001
Posts: 282
Check with DBA, some package need to be update on Oracle DB.
Harry Wood
Greenhorn

Joined: Jan 28, 2004
Posts: 16
I also saw
java.sql.SQLException: Io exception: Broken pipe
or sometimes
java.sql.SQLException: No more data to read from socket

I did manage to make the problem go away, but my fix is not very clean and efficient.

I'm working with an old JDBC version which doesn't provide 'DataSource' connection pooling, so I'm having to use DBConnectionBroker from javaexchange.com to connect to Oracle

This worked fine most of the time, but then DbConnectionBroker started returning dead connections, which cause the above errors when I run queries.

The trick is to detect dead connections before DBConnectionBroker returns them for use. It already has a 'housekeeping thread', which should find these dead connections, and reestablish them. It runs the checks every 20 seconds. Before it called connection.createStatement to see if the connection was still alive, but I found with oracle JDBC this test was not enough. It was allowing createStatement on a connection object which was dead (and destined to cause an error later)

I changed it so that it actually fires a query, to be absolutely sure the connection is alive:

stmt = connPool[i].createStatement();
ResultSet rset = stmt.executeQuery("SELECT SYSDATE FROM DUAL");

Although this must be a pretty fast query for the oracle server to cope with, it also an unnecessary query, which it is firing it every 20 seconds. So this seems like a bit of an ugly inefficient solution. Anyone have any better ideas for detected dead connection objects?
 
Consider Paul's rocket mass heater.
 
subject: Broken Pipe exception