Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9126451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:02:47+00:00 2026-06-17T07:02:47+00:00

We have a web server handling requests from clients. One component of this web

  • 0

We have a web server handling requests from clients. One component of this web server holds a connection to a database.

I need to be able to recognise if the connection has been closed or is in some way no longer functional before I begin to use it. Currently I do something like:

// Decide connection details on alias.
private String alias = null;
// I must have my own because I prepare statements.
private Connection connection = null;

public Connection getConnection() {
  try {
    if ( connection.isClosed() ) {
      // Start afresh.
      connection = null;
    }
    // ** More tests here to check connection is ok.
    if (connection == null) {
      // Make a new connection.
      connection = Connections.getConnection(alias);
    }
  } catch (SQLException ex) {
    // Cause a NPE further down the line.
    connection = null;
  }
  return connection;
}

Sadly this sometimes returns such a stale connection that I get one of various errors. One such looks like:

java.sql.SQLException: Io exception: Software caused connection abort: socket write error

Note that this is just one of the errors recorded and this one happens after about 72 hours idle.

What I am looking for is a minimal database-generic tester of a connection that should consistently tell if the connection is up, running and stable. Is this possible?

I don’t mind running a very small query against it but it must be both database agnostic and take little to no time/resources.

BTW: I am running under Java 5 so Connection.isValid is not a solution for me.


Added

For those of you visiting this question later – I eventually took the advice offered and moved to a real connection pool and not only was is astonishingly easy to do but all of my issues disappeared.

The only strange part was the realisation that with a connection pool you must close your connection when you are finished with it – the pool intercepts the close and returns it to the pool behind the scenes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:02:49+00:00Added an answer on June 17, 2026 at 7:02 am

    The best way is to do a simple SQL statement like SELECT 1 or SELECT 1 FROM DUAL for Oracle. (Please see your database for vendor-specific syntax.)

    If it fails, refresh the connection. That’s what Java EE app servers like WebLogic do to test them if you configure them to do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing a Windows-based web server handling multiple specific HTTP requests from clients
Say I have a web page like this on an Ubuntu 12.04 web server
We have a local server with an access database which feeds data to clients
I have a web server which I do not know what the time zone
I have a web server located in Switzerland and it is intended to serve
I have a web server which is protected behind http-basic-auth. I've read through the
I have a web project working perfecly on my web server and on my
I would like to have a web server displaying the status of 2 of
Can anyone explain if it is possible to have a web server for all
I have enabled the Web Server on my Mac OS X (10.5.6) by going

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.