java.sql.DataSource verification

From: Earl Hokens (earl.hokensREMOVETHIS_at_chi.frb.org)
Date: 01/21/04


Date: Wed, 21 Jan 2004 15:09:39 -0600

I am creating DataSource objects and storing them as a static variable
in a class. Since the DataSource object could always go bad or be
tossed out of the connection pool I can not always rely on the
DataSource object to be able to return valid connections to me. I want
to verify that the datasource object is still able to function when I
retrieve it.

Will a ds.getConnection() suffice for verification or will I need to
actually try to do something with the connection?

I want to have something like

public DataSource checkDataSource () {
        if (null != MyClass.ds) {
                try {
                        MyClass.ds.getConnection();
                } catch (SQLException e) {
                        MyClass.ds = getNewDataSource(MyClass.dsname);
                }
        }
}

Trouble is I don't know where it will fail and I don't know of anyway to
test such behavior.

Any suggestions?

Thanks,
Earl