How to perform cleanup for javax.sql.DataSource, like we do for java.sql.Connection

H

HalcyonWild

Hello all,

I am using a weblogic server. I am trying to get a connection from a
DataSource using following code.

I am not sure if I should do anything with the DataSource as part of
cleanup. There is no close method for DataSource, nor any other method
whose name suggests that it should be used for cleanup.

I am closing my connections, but what should I do with DataSource. Code
listing below.

Thanks. :)
====================
private DataSource src = null;
private final String DATA_SRC = "NonXADataSource";
private Connection getConnection() {
Connection c = null;
try {
if (src == null) {
src = DataSourceFactory.getDataSource(DATA_SRC);
}
c = src.getConnection();
return c;
} catch (SQLException ex) {
closeConnection(c);
throw new RuntimeException(
"Couldn't get connection for " + DATA_SRC, ex);
}
}

private static void closeConnection(Connection c) {
try {
if (c != null && !c.isClosed()) {
c.close();
}
} catch (SQLException se) {
logger.log("\n\n****************\n\nException while closing
connection", se);
}
}
=================
 
A

Adam Maass

HalcyonWild said:
Hello all,

I am using a weblogic server. I am trying to get a connection from a
DataSource using following code.

I am not sure if I should do anything with the DataSource as part of
cleanup. There is no close method for DataSource, nor any other method
whose name suggests that it should be used for cleanup.

I am closing my connections, but what should I do with DataSource. Code
listing below.

The DataSource interface provides no hook for cleanup. Particular
implementation of DataSource will have their hooks, if they need one.
Examine your documentation.

In WebLogic's case, I imagine the datasources bound to JNI through the
administration consoles are already being cleaned up at server shutdown, but
I also imagine that the exact behavior -- and what you must do, if
anything -- is documented somewhere in their (very large) documentation set.

-- Adam Maass
 
H

HalcyonWild

Adam said:
The DataSource interface provides no hook for cleanup. Particular
implementation of DataSource will have their hooks, if they need one.
Examine your documentation.

In WebLogic's case, I imagine the datasources bound to JNI through the
administration consoles are already being cleaned up at server shutdown, but
I also imagine that the exact behavior -- and what you must do, if
anything -- is documented somewhere in their (very large) documentation set.

-- Adam Maass

I went through weblogic docs and more importantly the examples. It
seems like the caller does not have to perform any cleanup. It is
automatically managed by Weblogic.

Thanks. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top