wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes Error Message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Error Message" Watch "Error Message" New topic

Error Message

Anshul Agrawal

Joined: Jul 15, 2008
Posts: 19
Hello All

I have made a service which connects to jdbc:microsoft:sqlserver and Process some tasks.

The service connects to database after every 10 min and process my code.All goes well.

But If the service is kept running for say 24 hrs it gives me error

[ [Microsoft][SQLServer 2000 Driver for JDBC]Connection reset by peer: socket write error]

The error is random means it not coming everytime.

I have checked the logs also, the server wasn't down.

I am trying with the validationQuery setting

private Connection getDBConn() throws SQLException, ClassNotFoundException {
Connection conn;


if ((dbName != null) && (!dbName.equals(""))) {
connectionURL = connectionURL + ";DatabaseName=" + dbName;
} else {
connectionURL = connectionURL + ";DatabaseName=master";

connectionURL.concat("?validationQuery=String 1");

logger.debug("Establishing Connection: " + connectionURL);

conn = DriverManager.getConnection(connectionURL, username, password);

return conn;

is this correct ?

Please suggest.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33106

Where do you close the connection? It sounds like the same connection is used for 24 hours which will result in a timeout. The alternative is to use a connection pool so the connection can reset itself as needed.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Anshul Agrawal

Joined: Jul 15, 2008
Posts: 19
No Jeanne
The connection is closed as the thread is completed in my finally block.

The error is random.
Misha Ver
Ranch Hand

Joined: Mar 03, 2008
Posts: 470
It sounds like something odd with the network.
Puja Mantri

Joined: Sep 24, 2009
Posts: 15
Could you pleae paste the output of following command:
netstat -a -b -v
I agree. Here's the link: http://aspose.com/file-tools
subject: Error Message
jQuery in Action, 3rd edition