Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
HalcyonWild - 17 Dec 2005 13:03 GMT
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);
       }
   }
=================
Adam Maass - 17 Dec 2005 16:49 GMT
> Hello all,
>
[quoted text clipped - 7 lines]
> 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
HalcyonWild - 19 Dec 2005 08:54 GMT
> > Hello all,
> >
[quoted text clipped - 18 lines]
>
> -- 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. :)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.