Ensure that everything is closed?

Hello,
I am using Sun Java Application Server 8 and Oracle 9i. I know that if you don't close all of your ResultSets, Statements and Connections, you'll get a error like "Error in allocating a connection. Cause: In-use connections equal max-pool-size and expired max-wait-time. Cannot allocate more connections.". When that happens you are pretty much hosed.
You can't just do a blanket try - catch, because depending upon where the error occurs, different objects are created, so you don't know which ones to close.
I started using a double try catch, like this
try {
Context initCtx = new InitialContext();
DataSource ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/newsAdmin");
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
try {
// blah blah blah
ResultSet rss = stmt.executeQuery("select * from my table");
// blah blah blah
rss.close();
} catch (Exception e) {
stmt.close();
con.close();
throw e;
stmt.close();
con.close();
} catch (Exception e) {
But there are still situations where something does not get closed. What is the plain vanilla way to ensure that everything gets closed? Also, is there a way to have the Servlet close everything on redirect? What about an application server setting? This seems pretty damgerious. One developer having a bad day could put code out there that locks up the applicaion server.
Thanks
Mike

public void foo()
   throws SQLException {
   Connection conn = null; 
   PreparedStatement stmt = null;
   ResultSet results = null;
   try {
         // create connection, statement and result set normally
    finally {
         closeResources(conn, stmt, results);
private void closeResources(final Connection conn, final Statement stmt, final ResultSet results) {
   if (results != null) {
       try {
           results.close();
       catch (SQLException ignroe) {
            ignore.printStackTrace();
   if (stmt != null) {
       try {
           stmt.close();
       catch (SQLException ignroe) {
            ignore.printStackTrace();
   if (conn != null) {
       try {
           conn.close();
       catch (SQLException ignroe) {
            ignore.printStackTrace();
}If you have more than one database operation that needs closing (which is likely the case), consider moving closeResources() to another helper object as a static method.
- Saish

Similar Messages

  • Im syncing my iphone to itunes because i cant unlock the phone due to water damage so that i can take what is on it and put it on a new phone. how can i ensure that everything was taken from the phone and where can i find it in itunes?

    my phone recently suffered water damage so that the screen does not reigster when i slide to unlock. I am sycing the data from the phone onto itunes so i can put it onto a new phone. How can i ensure that i took everything off of the old phone before i restore it and where can i find all of that stuff when i sync with the new phone?

    iTunes will only store a back up of the iPhone and you find this by following the steps below:
    Windows
    Edit>Preferences>Devices
    Mac
    iTunes>Preferences>Devices
    The link below can show you what is stored in an iTunes back up:
    iTunes: About iOS backups

  • I have a 3GS iPhone, version 3.1.2.  I have never plugged my phone into a computer or synced with iTunes.  If I do so now, I will I lose everything?  What steps need to be taken to ensure that all of my data, contacts, photos, etc. are not lost?

    I have a 3GS iPhone, version 3.1.2.  I have never plugged my phone into a computer or synced with iTunes.  If I do so now, I will I lose everything?  What steps need to be taken to ensure that all of my data, contacts, photos, etc. are not lost?

    IOS: how to back up  http://support.apple.com/kb/HT1766

  • My iPhone will not send an iMessage. It sends everything as SMS. I have ensured that my Apple ID is signed in and that my phone number is enabled for use in both FaceTime and iMessage

    My iPhone will not send an iMessage. It sends everything as SMS. I have ensured that my Apple ID is signed in and that my phone number is enabled for use in both FaceTime and iMessage

    I had the same problem. I went in and added my email address to iMessage and deleted the text to my friends that have iPhones and sent another to test it and it worked. Only thing is now my non iPhone friends don't receive my pic text. I had to turn off iMessage for it to work. Apple needs to fix this ASAP!

  • With a PDF Dynamic form using show/hide actions, how to ensure that when the completed form is saved, closed and re-opened, the form still show the fields as before it was closed?

    With a PDF Dynamic form using show/hide actions, how to ensure that when the completed form is saved, closed and re-opened, the form still show the fields as before it was closed?
    I have developed a form with fields hidden by default, that become visible based on box ticked or radio button selections.
    My problem is that, when I close the form and re-open it, it comes back to it's default presentation, regardless of the information already recorded in the form (including in the now hidden fields.
    How to correct that
    Thanks in advance for any hint you can provide.

    I've had the same problem. This solved it...
    Go to the "Form properties..." in the File-menu. Select "Run-time" to the left and in the box "Scripting" Preserve scripting changes to form when saved: choose Automatically (Script-based state changes are saved locally in an insecure fashion. This option cannot be used for certified forms).
    Hope it works for you to...

  • My iPad says that she is busy and is unable to accept my request even when everything is closed and nothing is being used. What might be the problem here?

    My iPad says that she is busy and is unable to accept my request even when everything is closed and nothing is being used. What might be the problem here?  3 times my iPad has crashed while nothing was open or running and a small loading wheel would be moving signifying that the thing was loading something without permission.  Even when the dang thing was on my personal wireless service that I pay for.

    similar to what is happening to me....the difference is, after restoring itunes detect ipod and ask to restore again and again....
    I know it may look kinda stupid but: just leave the ipod there for about 2 minutes, that's about the time my itunes is taking to detect my ipod...if it doesn't work, try connecting ur ipod to other computer with itunes (no need to sync, just to check if itunes will recognize) to check if the problem is with the ipod or with the itunes and/or computer.

  • I own a ipad mini and a iPod touch , both configured on the same apple account, how do I ensure that my data on the ipad mail,notes,pics etc is not visible/accessible on the ipod

    I own a ipad mini and a iPod touch both configured on the same id
    How do I ensure that my data on the ipad mail,notes,pics etc is not visible/accessible on the iPod touch when the iPod is connected to a wi fi connection

    Mail: do not have the same account loaded onto the two devices.
    Photos: go into Settings->Photos & Camera->and turn off photo stream.
    everything else, sign out of the Apple ID on the device you dont want to be visible.
    good luck

  • Everytime i restart my macbook, it always opens all apps that i have closed before even though i have unticked not to reopen windows during login

    Every time i restart my mac, it always reloads the same apps that I have closed, even though before i shut down i have closed everything.
    Anyone got the solution?
    thanksss

    I have the same problem on my notebook but I don't restart. Just do the control, alt, delete and bring up your task manager. Then scroll down to Firefox, end process and close. Now you should be able to restart FF. Not a fix but better than having to restart your laptop.

  • [svn:osmf:] 10248: Fix a few bugs related to the interaction between IPlayable, IPausable, and ITemporal within a SerialElement, specifically around ensuring that the transition from child to child happens in the various permutations of these traits .

    Revision: 10248
    Author:   [email protected]
    Date:     2009-09-14 16:45:00 -0700 (Mon, 14 Sep 2009)
    Log Message:
    Fix a few bugs related to the interaction between IPlayable, IPausable, and ITemporal within a SerialElement, specifically around ensuring that the transition from child to child happens in the various permutations of these traits.  Introduce a helper class for managing this logic, as it can happen in both CompositePlayableTrait and CompositeTemporalTrait.  This lays the groundwork for a MediaElement which only implements IPlayable (e.g. to ping a tracking server) working within a serial composition.  Beef up unit tests so that these cases don't get broken in the future.
    Modified Paths:
        osmf/trunk/framework/MediaFramework/.flexLibProperties
        osmf/trunk/framework/MediaFramework/org/openvideoplayer/composition/CompositePlayableTrai t.as
        osmf/trunk/framework/MediaFramework/org/openvideoplayer/composition/CompositeTemporalTrai t.as
        osmf/trunk/framework/MediaFrameworkFlexTest/org/openvideoplayer/composition/TestSerialEle ment.as
    Added Paths:
        osmf/trunk/framework/MediaFramework/org/openvideoplayer/composition/SerialElementTransiti onManager.as

    Hi,
    Found a note explaining the significance of these errors.
    It says:
    "NZE-28862: SSL connection failed
    Cause: This error occurred because the peer closed the connection.
    Action: Enable Oracle Net tracing on both sides and examine the trace output. Contact Oracle Customer support with the trace output."
    For further details you may refer the Note: 244527.1 - Explanation of "SSL call to NZ function nzos_Handshake failed" error codes
    Thanks & Regards,
    Sindhiya V.

  • I'm having a loading sign on top of my screen when everything is closed

    I'm having a loading sign on top of my screen when everything is closed

    How do you know "everything is closed"?
    Applications are likely still running.  You can double click the home button to view what they are.  (Single click it again to remove that display).
    Even if you don't see applications running there, the chances are your mail app is sensing whether there is new mail for you.

  • HT3819 I have synced my ipad and iphone 5 to itunes and all my songs appear in the device library but i cannot ply all of the songs unless via home sharing. How can i ensure that my libraries appear on each device as the syncing process seems to be failin

    Syncing problems.
    How can I sync my iphone 5 and ipad to ensure that i dont need to use home sharing to access all of my music library?

    I don't think I have made myself clear... I have recently upgraded my iPhone 4 to a 5 so everything was set up to sync with no problems at all. I transferred everything across to my new device by iCloud and everything appears as it was on my old device including on the face of it my music library. However, I cannot play all of the songs in fact the majority! When at home I can access the entire library via home sharing but that is no use away from the house. I never had this problem with iPhone 4 and although I am automatically syncing the device to iTunes it is not working. If I try to play songs via the device it skips until it finds a song that cAn be played and if I try and play the device via the laptop/iTunes an ! Type signal appears and I cannot play the song!
    Any ideas re solutions would be appreciated???

  • How can I ensure that Printing Defaults are reset on the clients?

    Hi,
    we have a setup with a Windows Server 2008 print cluster and a mix of Windows XP and Windows 7 clients. On all clients the users are local admins.
    When the install a new print queue the Printing Preferences at the client is set to the "correct" values, meaning the values that we have set on the server. But if they change the settings (e.g. from Black/White to Colour) the setting is kept even after
    the application is closed.
    Either things have changed over time or the issue is caused by letting the users be local admins, but I beleive that the settings where previously set back to defaults once the application, from where the settings where changed, was closed.
    Can someone please tell me how to ensure that users do get the servers Printing Default forced on to them and that settings changed within an application is lost when closing the application?
    Thanks for your help - it is much appreciated!
    Best regards
    David

    I see it's a quite old post but still without an answer.
    What follows it's not exactly what David asked for (application-aware reset of printing defaults).
    I ended up here searching for a way to refresh printing defaults on clients without having users to remove/add printers manually. I hope this helps someone.
    A viable solution might be to create a login vbs script deleting -> adding all network printers currently installed on the user profile. Default printer setting is not affected.
    Tested on Windows 7 x64 clients and 2008 R2 print server.
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
    For Each objPrinter in colPrinters
    If InStr(objPrinter.DeviceID, "\\") = 1 Then
    UNCPrinter = objPrinter.DeviceID
    objPrinter.Delete_
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection UNCPrinter
    End If
    Next

  • I need to ensure that the data environment is restored when user is returned to the main form

    Greetings...
    VFP 9.0 SP2, Win7 workstations, Server 2008
    I have a form that contains many grids, the various tables have a relationship and everything works as it should.  
    The main form gives users the ability to run other forms and programs. When a user is returned to the main form, is there a way to ensure that the data environment is back to the way it was prior to call to
    the other form/program?  I have tried create view/set view and I believe that would do what I want but when the set view command is issued, the grids are empty.   
    As always, any advice/suggestions are greatly appreciated.
    Thank you.

    Bob has it in very short.
    If you want something to stay as it is, you don't do anything to it.
    That sounds easy, but it means all your other forms have to use private data sessions to not disturb any state in the main form.
    A forms dataenvironment is its definition of data to be opened. CREATE VIEW / SET VIEW is really just very basic and won't reconstruct everything, eg no record positions. While it reestablishes relations, this won't give you the situation you left, simply
    because record positions are not saved, cursors are not saved, so all data queried while working is lost.
    You may save more info, if you really want to reconstruct a situation after restarting the application. Then you have to save IDs (better than saving recnos) and reconstruct everything.
    What is more workable is saving query parameters to find and navigate to the the same data again.
    Bye, Olaf.
    Edit: Don't take "query parameters" too literal. This might be view parameters, but can be anything you use as search criteria to let users get to their current display of data.
    Olaf Doschke - TMN Systemberatung GmbH
    http://www.tmn-systemberatung.de

  • Application launch failed. Ensure that the device screen is unlocked - after the phone update

    I have the following error "
    Error    1    Application launch failed. Ensure that the device screen is unlocked and device is developer unlocked. For details on developer unlock, visit http://go.microsoft.com/fwlink/?LinkId=195284.         0    0 
    I'm pretty sure it happened after the last update. I was able to use my phone as a dev one before
    and my account shows it as a registered device.
    The OS version is 7.10.8107.79.
    The steps that I tired
    -Registered again my phone with the registration tool
    -Check the issue with Zune auto-launcher (zune isn't syncing and the phone is connected)
    -Close and start everything again
    Other possible issues
    - Do I have to have sdk 7.1 to deploy?
    - Do I have to wait 24h for registration?

    You should be using SDK 7.1 anyway, so install that.
    After the update, the phone may have locked itself.  This may not be reflected in your AppHub account though.  Using the Developer Registration Tool, register the device, unregister it, then register it again.

  • Ok Apple users...Is there a way to delete e-mails on my Mac and not have to delete the same e-mails on my iPhone, and iPad...and vise-versa. I have the Cloud, and thought that everything would sync all of the time. If you know of a setting I need to adjus

    Ok Apple users...Is there a way to delete e-mails on my Mac and not have to delete the same e-mails on my iPhone, and iPad...and vise-versa. I have the Cloud, and thought that everything would sync all of the time. If you know of a setting I need to adjust, please let me know.

    Are you referring to @mac.com, @me.com or @icloud.com emails? Or some other email providers emails?
    If the former, it should do that automatically. If the latter, no. iCloud does not (nor is it supposed to) sync non-Apple provided emails.

Maybe you are looking for

  • Is it possible to find the creation date of a CD/DVD burned on Mac OS 8.6 either on newer mac or Windows machine?

    I am cataloguing lot of my old music and data cds/dvds. Some of these were created on my old Mac (OS 8.6). I was wondering if there was a way to check the metadata on these discs on my current Windows machine or on a Mac that I have at work to get th

  • Question about VPN on RV082

    Question about VPN on RV082 i connect like diagram when i use shrewsoft for vpn ipsec i can not connect across rv082 to next hop on wan 1 but when i use PPTP on windows 7 for vpn PPTP i can connect across rv082 but high latency on this connection ple

  • Send XML File as attachement in Mail Receiver adapter

    Hi all, i have the following scenario. i would like to read an XML file from the file system and send this file as an attachement of a mail to a mail receiver specified in this file. i would like to fill the payload of the mail with some information

  • Powerbook G4 12" - Mac OS Supported

    What is the most current version of the MacOSX that can be installed on a powerbook g4? Currently running 10.3.9.

  • How the transaction executing in Oracle bpm 10g

    Hi, i want to know "how the database transaction executing in Oracle bpm 10g", My Scenario is 'i have two data tables, i need to update the same information in two different data tables with OBPM 10g. let's imagine, info is updated in 1st data table,