473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Reestablishing a db connection after a network failure

Hi,

I have the following problem: I am implementing a server in Java and
I use jdbc to connect to an Oracle 9.0.2 db. All seem to work fine,
but when I intensionally cause a network failure (i.e. I remove the
network cable) I get the following exception:

java.sql.SQLException: Io exception: Connection reset by peer: socket
write error

I plug the cable again and I want to reset the java.sql.Connection but
this seems to not work. Any suggestions?
Jul 19 '05 #1
2 6789

Followups directed to comp.lang.java.programmer.
Pandis Ippokratis wrote:
I have the following problem: I am implementing a server in Java and
I use jdbc to connect to an Oracle 9.0.2 db. All seem to work fine,
but when I intensionally cause a network failure (i.e. I remove the
network cable) I get the following exception:

java.sql.SQLException: Io exception: Connection reset by peer: socket
write error

I plug the cable again and I want to reset the java.sql.Connection but
this seems to not work. Any suggestions?


There may be an option you can use when you set up the connection that
will instruct the driver to attempt to reconnect automatically. The
details and implications should be considered carefully. The MySQL JDBC
driver distributed by MySQL has such a feature, although I'm not sure
whether it handles all cases of connection interruption.

Alternatively, you can wrap the Connection provided by your driver in an
object that handles the details of this scenario, which might include
obtaining a new Connection to replace the interrupted one. If you make
this new object implement Connection itself (and delegate to the
internal collection) then it would be a drop-in replacement. You must
again be careful to consider all the implications, however. For
instance, there are various aspects of DB-side state that are tied to
specific connections; in particular, transactions. There are also
Java-side entities that are tied to specific Connections and would
require considerable additional work to support transparently -- most
particularly Statements and ResultSets.

The best choice may be to better isolate the DB interactions from the
rest of your code so that you can handle exceptions in a sensible way
but in a single place. Implement the Data Access Object pattern, for
instance, and make your data access objects sufficiently smart. If you
need to do so then put a facade around more complicated DB access
activity that knows how to deal with these problems (and others). This
could all be implemented with EJB, which would have some advantages, but
could also be implemented in normal Java code.
John Bollinger
jo******@indiana.edu

Jul 19 '05 #2
Most connection pool implementations handle this sort of thing, with
the added benefit of higher performance.

Apache has a connection pools architecture in their common package:

http://jakarta.apache.org/commons/dbcp/

Or, you can roll your own... it's fairly easy to implement the JDBC
interfaces. Sun had a tutorial on their website at one time
(java.sun.com), but I can't find anymore.

//Nathan

ip********@cmu.edu (Pandis Ippokratis) wrote in message news:<8a**************************@posting.google. com>...
Hi,

I have the following problem: I am implementing a server in Java and
I use jdbc to connect to an Oracle 9.0.2 db. All seem to work fine,
but when I intensionally cause a network failure (i.e. I remove the
network cable) I get the following exception:

java.sql.SQLException: Io exception: Connection reset by peer: socket
write error

I plug the cable again and I want to reset the java.sql.Connection but
this seems to not work. Any suggestions?

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: middletree | last post by:
Sorry for the crosspost (I posted this on the asp.db group last night). But since I had no answer there, I'm hoping for better luck here. I'm pretty much tried everything I know. Here's the...
2
by: Diffident | last post by:
Hello All, I am trying to redirect users to a standby webpage in case our application is down due to database server failure. To facilitate this I am opening a test connection within a try/catch...
1
by: Chris Love | last post by:
I have already asked this, but no one seems to know the answer. Here is the timeline. I wanted to use the membership/roles functionality in a site. I got all sorts of errors trying to get this...
0
by: Tor Inge Rislaa | last post by:
Just for testing deployment of an asp.net application to the remote server I have crated an application based on the StarterKit application in Visual Studio 2005. When trying to run the...
1
by: Marty | last post by:
Just starting to learn this and that could be my problem. I am using VS 2005, SQL Server Standard In the server explorer I can see and test my database connection and it works. I am trying a...
1
by: Vikram S | last post by:
Hi All, I have an ASP.NET 2.0 web application on a web server and a separate machine for SQL Server 2000 Database. I am using a Connectionstring based on Sql Authentication to connect to the...
2
by: Pandis Ippokratis | last post by:
Hi, I have the following problem: I am implementing a server in Java and I use jdbc to connect to an Oracle 9.0.2 db. All seem to work fine, but when I intensionally cause a network failure...
0
by: mina | last post by:
My application which is written in vb.net 2005 uses sql server 2005 express as a database, this application is multi-user. So i am used 3 xp machine to install my application i can say...
1
by: john20 | last post by:
Hi All, I have recently installed Sql server 2005 on my machine and i am trying to connect to database for retreiving table information. but it is giving me below error : An error has...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.