This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Broken Pipe exception
 
Similar Threads
tomcat with Oracle DB access problem
struts - oracle datasource
Struts - Oracle Data source
spring / ibatis issue
java.sql.SQLException: Io exception: Got minus one from a read call