473,385 Members | 1,593 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,385 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 6787

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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.