Closing a connection in "finally {...}"

Hello!
I have a connection pool constantly growing in an OC4J in an Oracle 9iAS. My question is kind of "basic", but I need to find the "leak":
In the Handler-classes I close the resultsets, statements and connections in a finally-block, but return-values (if any) are returned in the try-block. Will the finally-block ever be executed if no exceptions are caught? Obviously that is my assumption, but I'd appreciate a confirmation or correction.
try {
Connection con = ...;
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("...");
ArrayList sampleStrings = new ArrayList();
while(rs.next()) {
String example = rs.getString(1);
sampleStrings.add(example);
return sampleStrings;
catch(...) {...}
finally {
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
if(!con.isClosed() && con!=null) con.close();
BR,
Herman Svensen

Hi Herman,
Will the finally-block ever be executed if no exceptions
are caught?Of-course it will. The "finally" block is always executed.
The OTN forums don't recognize HTML tags. Like a lot of other forum sites, the OTN forums use special tags known as UBBCode. Unfortunately, the OTN forums seem to recognize a very limited set of these tags. The only two tags which always seem to work (regardless of which Web browser I use) are:
[ url ]
[ code ]
Note: The spaces are added intentionally, so that they won't be recognized. When you use them in your post, remove the spaces.
The JavaRanch forum has a Web page that explains UBBCode.
Good Luck,
Avi.

Similar Messages

  • Getting Error:closing a connection for you. Please help

    Hello All,
    I'm using jboss3.2.6. I used ejb2.1 (session bean and entity bean[BMP]). I did few data base transations in cmp and few in simple data source connection.
    I'm getting below errors occasionally
    'No managed connection exception
    java.lang.OutOfMemoryError: Java heap space
    [CachedConnectionManager] Closing a connection for you. Plea
    se close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@11ed0d
    5
    I've given below my dao connection code here,
    package com.drtrack.util;
    import java.sql.Connection;
    import java.sql.SQLException;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;
    public class DAOUtil {
    private static DataSource _ds;
    public Connection con;
    public DAOUtil() throws SQLException {
    try {
    if (_ds == null)
    assemble();
    if(_ds != null && con == null) {
    con = _ds.getConnection();
    }catch(SQLException ex) {
    ex.printStackTrace();
    private void assemble() {
    Context ic = null;
    try {
    ic = new InitialContext();
    DrTrackUtil drutil = new DrTrackUtil();
    _ds = (DataSource) ic.lookup("java:/" + drutil.getText("SOURCE_DIR"));
    drutil = null;
    }catch (Exception e) {
    e.printStackTrace();
    }finally {
    try {
    ic.close();
    }catch(NamingException ne) {}
    public void closeConnection() throws SQLException {
    if(con != null)
    con.close();
    con = null;
    }below is the code with get connection and doing transaction in it.
    public static AccountMasterValueBean getAccountMasterByAcctId(String acctId) {
    AccountMasterValueBean bean = null;
    DAOUtil dao = null;
    CallableStatement cst = null;
    ResultSet rs = null;
    try {
    dao = new DAOUtil();
    cst = dao.con.prepareCall(DrTrackConstants.MSSQL_USP_ACCOUNTMASTER_BY_ACCTID);
    cst.setObject(1, acctId);
    rs = cst.executeQuery();
    if(rs != null && rs.next()) {
    bean = new AccountMasterValueBean(
    Integer.valueOf(rs.getString("accountkeyid")),
    rs.getString("latitude"),
    rs.getString("longitude"));
    }catch(SQLException se) {
    logger.info("SQL Error: " + se);
    finally {
    if(rs != null){
    try {
    rs.close();
    }catch(SQLException se) {
    logger.info("SQL Error: " + se);
    finally {
    rs = null;
    if(cst != null) {
    try{
    cst.close();
    }catch(SQLException se) {
    logger.info("SQL Error: " + se);
    finally {
    cst = null;
    if(dao != null) {
    try {
    dao.closeConnection();
    }catch(SQLException se) {
    logger.info("SQL Error: " + se);
    finally {
    dao = null;
    return bean;
    }I closed connections, resultsets and statements properly.
    Why I'm getting these errors.? Where I'm doing wrong. ? Please help me. I have to fix them ASAP.
    Thanks.

    Hello All,
    I'm using jboss3.2.6. I used ejb2.1 (session bean and entity bean[BMP]). I did few data base transations in cmp and few in simple data source connection.
    I'm getting below errors occasionally
    'No managed connection exception
    java.lang.OutOfMemoryError: Java heap space
    [CachedConnectionManager] Closing a connection for you. Plea
    se close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@11ed0d
    5
    I've given below my dao connection code here,
    package com.drtrack.util;
    import java.sql.Connection;
    import java.sql.SQLException;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;
    public class DAOUtil {
    private static DataSource _ds;
    public Connection con;
    public DAOUtil() throws SQLException {
    try {
    if (_ds == null)
    assemble();
    if(_ds != null && con == null) {
    con = _ds.getConnection();
    }catch(SQLException ex) {
    ex.printStackTrace();
    private void assemble() {
    Context ic = null;
    try {
    ic = new InitialContext();
    DrTrackUtil drutil = new DrTrackUtil();
    _ds = (DataSource) ic.lookup("java:/" + drutil.getText("SOURCE_DIR"));
    drutil = null;
    }catch (Exception e) {
    e.printStackTrace();
    }finally {
    try {
    ic.close();
    }catch(NamingException ne) {}
    public void closeConnection() throws SQLException {
    if(con != null)
    con.close();
    con = null;
    }below is the code with get connection and doing transaction in it.
    public static AccountMasterValueBean getAccountMasterByAcctId(String acctId) {
    AccountMasterValueBean bean = null;
    DAOUtil dao = null;
    CallableStatement cst = null;
    ResultSet rs = null;
    try {
    dao = new DAOUtil();
    cst = dao.con.prepareCall(DrTrackConstants.MSSQL_USP_ACCOUNTMASTER_BY_ACCTID);
    cst.setObject(1, acctId);
    rs = cst.executeQuery();
    if(rs != null && rs.next()) {
    bean = new AccountMasterValueBean(
    Integer.valueOf(rs.getString("accountkeyid")),
    rs.getString("latitude"),
    rs.getString("longitude"));
    }catch(SQLException se) {
    logger.info("SQL Error: " + se);
    finally {
    if(rs != null){
    try {
    rs.close();
    }catch(SQLException se) {
    logger.info("SQL Error: " + se);
    finally {
    rs = null;
    if(cst != null) {
    try{
    cst.close();
    }catch(SQLException se) {
    logger.info("SQL Error: " + se);
    finally {
    cst = null;
    if(dao != null) {
    try {
    dao.closeConnection();
    }catch(SQLException se) {
    logger.info("SQL Error: " + se);
    finally {
    dao = null;
    return bean;
    }I closed connections, resultsets and statements properly.
    Why I'm getting these errors.? Where I'm doing wrong. ? Please help me. I have to fix them ASAP.
    Thanks.

  • Difference between closing the connection before and after committing user transaction?

              I was wondering what's the difference between closing the connection before committing
              the transaction versus closing the connection after committing the transaction?...
              for e.g....
              Scenario 1.........
              UserTransaction useretran;
              usertran.begin();
              Connection con = datasource.getCOnnection();
              // do bunch of stuff...
              conn.close();
              usertran.commit()
              Scenario 2...
              UserTransaction useretran;
              usertran.begin();
              Connection con = datasource.getCOnnection();
              // do bunch of stuff...
              usertran.commit()
              conn.close();
              thanks....
              Srini
              

    Hi. As long as you're sure there's a transaction going on, and the connection
    is a transaction-aware object (from a TxDataSource), either will be fine.
    In the first scenario the actual semantics of the close() call are less than
    normal, because we really don't close the connection or return it to the
    pool until the actual transaction commits, and in the second case, we have
    already taken the connection out of your service as of the commit().
    The second scenario is the usual coding style. If there's ever a chance your
    code will get non-transaction-aware connections, it is crucial to close
    connections, and I always recommend putting the close() in a finally block
    so it's guaranteed to happen.
    Joe
    srinivas wrote:
    I was wondering what's the difference between closing the connection before committing
    the transaction versus closing the connection after committing the transaction?...
    for e.g....
    Scenario 1......... UserTransaction useretran; usertran.begin(); Connection con =
    datasource.getCOnnection(); // do bunch of stuff... conn.close(); usertran.commit()
    Scenario 2... UserTransaction useretran; usertran.begin(); Connection con = datasource.getCOnnection();
    // do bunch of stuff... usertran.commit() conn.close();
    thanks....
    Srini

  • Video cameras no longer connecting to Final Cut Express

    I have two video cameras (Sony TRV-25 and Sony HDV-A1U) which are no longer connecting to Final Cut Express through the firewire (4-pin to 800). I get the "unable to initialize" message. What's weird is that they were working fine just last month.
    I'm on a relative new iMac, running 10.6, FCE 4.
    I've double and triple-checked the settings on the cameras (i.e., HDV and iLink output settings), and I've selected the appropriate settings in Easy Setup in FCE (1060i60 for the HDV, NTSC-DV for the TRV).
    I also reset video devices under the View menu.
    Just for kicks, I tried connecting the TRV-25 to my old Mac. I had no problems at all. [The old Mac won't work with the HDV camera, so I didn't bother trying that.]
    There are no other firewire devices connected to the Mac. There is an external drive that I use for capturing the video files that is attached through one of the USB ports.
    I went and bought another firewire cable just to make sure, but got the same results.
    For what it's worth, I also could not get the cameras to be recognized in iMovie.
    Is there anything else I should try?
    Thanks!

    When I looked in System Profiler and click on the firewire line, it just said something about maximum speed 800 MB per second or whatever. Should it actually have the camera listed there? Is that the right way to check?
    The firewire is 4-pin (iLink) to 800, and there are no other devices connected.

  • Is there anyway to solve Wifi problem on Macbook while using it closed and connected to external display?

    Hello,
    I'm using my Macbook connected to external LCD while the screen of the Macbook is closed. So I can use the full screen resoluiton of my LCD. When not closed but connected the mirroring reduces the resolution and not useful.
    But recently I recognized that when the Macbook screen is closed my fiber internet speed is down almost %50. When I test my fiber speed, when the macbook screen is open it's around 20mb/s, when the screen is closed and connected to LCD it's around 10 mb/s. I guess the wifi antenna is located at the screen I don't know. Is there any way to solve this probem? I want to use the lid closed without any sacrifice from my internet speed.
    Thanks for any answers in advance

    I have this same issue but what's strange is that it's only recently occurred since upgrading to FiOS's 50MB/s service.  I was seeing 20MB/s WiFi speeds with my previous 25MB/s service.  Frustrating!!

  • Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.

    Hi,
    I am using APEX version 4.2.1.00.08 with Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    I've developed an application, that was working fine till 3 days ago...
    At the moment, I can log into the application but when I enter my ID/PW it takes me to my 1st page but then it runs for a mint or so (trying to load charts) and then generates following error message
    No data received
    Unable to load the webpage because the server sent no data.
    Here are some suggestions:
    Reload this webpage later.
    Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
    interestingly, I haven't changed anything within the application
    I've tried it with Chrome Version 27.0.1453.116 m and IE 8.0...
    with IE 8.0, it shows I/O Error in place of my graphs and get's a pop up message that displays "Error - error unknown"
    The only thing that I can recall doing differently is logging via remote desktop connection, but I've used remote desktop in the past as well and it worked.
    Please advice

    anyone...?

  • Closed database connection in olap worksheet

    i have installed analytic workspace manager after applying the pathches ,i tried to log in analytic workspace manager and connect to olap worksheet it gives
    me an error as "closed database connection" .My patch
    installation was successful and it did not give me any error and my database is also working properly.could anyone help me out with this problem.

    I had the same problem. Follow this link for the solution
    Re: Cannot connect to AWM

  • Gateway unexpectedly closed the connection..

    When I try to Test Connection for the Active Directory Resources it shows the following error
    The gateway unexpectedly closed the connection with an exception, check the gateway trace for more information. ==> java.net.SocketException: Connection reset by peer: socket write error
    Previously it has working fine for me...

    Kannan SB wrote:
    I Have resolved my issue... I had remove the Gateway service and reinstall the service & restart the machine and try it got success...Still I have face the same issue, only it works for sometime I means while we restart the service it will work after some mins it got failed to perform the service.. Please suggest me for that....
    I have migrated Sun Identity Manager 8.1 Patch 7 to Oracle Waveset 8.1.1 Still the issue persists ...

  • Closing DB Connection-Best Practice

    Currently I am opening and closing my connection to the database on each event that warrants a database connection. Is this the way I should handle it, or should I open the connection at the beginning and close it at the end, leaving it open in between?
    I have a certain panel that has numerous, separate inputs to a database that are isolated from each other, and if I happen to use all of these inputs, I open and close the connection 3 or 4 times.
    Thanks

    Hi,
    As far as an application is concerned we usually wont advice opening and closing connection as and when necessary. But if the connection is open for a long time there are some possible problems. One is that if the server goes down the user wont be aware of that till he executes the next query and also the error wont will be a valid one.Next is the amount of time ther server holds the connection and this has its significance if max. number of connections is specified.
    So again, its upto you to decide what all conditions are applicable to you. Its actually a trade-off between reliability and performance. :-)..
    regards Stallon

  • The VI closed the connection : error 1074360302 at property node(arg 1)

    hi!
    I'm trying to running a code which apply the control of my myRIO through a VI on my host computer. A video stream of data is also going to be send from myRIO to the Host Computer VI. However, I am getting the "Host Computer VI" closed the connection. I have no idea why.
    And at the Host Computer keep giving out error 1074360302 occured at Property Node (arg 1) in myRIO vi.
    I would be glad if someone could help me.
    Thank you.
    Attachments:
    Picture1.png ‏81 KB

    Hi e_pah,
    Thanks for your response, what sort of camera are you using? This error has been previously seen with a Stingray camera when the IMAQ drivers aren't quite up to date.
    So firstly, we need to make sure the IMAQ drivers are updated.
    Further questions regarding your application:
    Did this VI ever run?
    Does this error occur everytime the VI is run?
    What is the the property node doing?
    Many thanks
    Ingram

  • Message cannot be transferred to node SMTP due to connection error (final)

    HI Gurus,
    we are gewtting the following error inour test client in SOST transaction. Can someboyd please thriw soem light on how to resolve this?
    Message cannot be transferred to node SMTP due to connection error (final)
    Message no. XS816
    Diagnosis
    Due to a technical fault, the system could not set up a connection to the RFC destination Check port and mail server for SMTP nodes. Therefore, the message could not be transferred to node SMTP.
    System Response
    The system was unable to transfer the message.
    Additional information of the node used (in the system language of the node):
    Procedure
    Check the connection from SAP system to node SMTP. Perhaps the node is not assigned to the correct RFC destination. If so, correct this in Customizing.
    Otherwise use RFC destination management to check the RFC connection to destination Check port and mail server for SMTP nodes.
    If R/3 is in productive operation, it is advisable to reroute provisionally to another node.
    You should therefore notify your system administrator.
    Thanks
    Anusa

    Yes i completely agree, but we wanted to test this process by putting our own email addresses in the vendor master and then also maintinaing the condition records to make sure that the email are coming fine. I guess it was working until some time, but then yesterday i noticed this error message in our test client. Somehow we need tthis to get working so that we can get the signoff from the business and that this can be moved to production
    Thanks
    Anushga

  • Univers Designer : JZ0C1, IOException closed the connection

    Hi !
    We get a very strange error when we work in Univers Designer (we're in BO 4.1) when we're working with Derived Table.
    For some reason when we edit a Derived table in a universe (connected to a Sybase database), we received an error message "JZ0C1" saying that we get an IOException and it's closed the connection.
    We get the error message when we click on "Check Syntax" Button in the edit window of the derived table.

    This can mean that the target end has already closed without reading all the data you are trying to send.

  • The remote device closed the connection!!! HELP

    Hi,
    Brought the Ms-6967 Bluetooth USB adapter so I could connect it to my nokia 7650. But have had big problems which failed in me getting anything out of the product.
    For starters every time I reboot my pc, I have to re-install the driver for the Bluetooth dongle? because my operating system (XP) finds this hardware every time I reboot and doesn't seem to remember the last time I install it.
    Plus when I use the software it actually communicates with my Nokia 7650 as in sending a message asking for permission to link pc to phone and when I answer yes on my nokia it replies with " The Bluetooth serial port connection failed: The remote device closed the connection?
    I've wasted so many hours now on this and had no luck. So if anyone has the smallest piece of help to give I would be well happy,
    Cheers,
    DRGonzo247

    Having seen similar symptoms recently you might want to check that you haven't had a browser hijacker installed - check your proxy settings to see if the browser is trying to use a proxy server, or, if you usually use a proxy, check to make sure it hasn't
    been changed. (In IE go to Tools->Internet Options->Connections->Lan Settings.)
    Good luck!

  • Iphone not connecting to final cut

    I can't get my iPhone to connect to final cut for import.  Ever since I downloaded the new update for Final cut x, I have had problems connecting. The new import box doesn't show the iPhone is connected.

    nevermind, my drivers weren't updated!!
    It works now!! thanks

  • The underlying connection was closed: A connection that was expected to be kept alive was closed by the server

    Dear forum 
    Please help
    I'm running an application that receive some messages (mail)
    I'm running under server 2012.
    For some reason the messages are stop to being received due to the session that is being closed.
    i can read the log saying:
    HTTPS ReceiveProcess(): Null segement received
    Closing session, dispatch Timer: 60000 ms.
    The underlying connection was closed: A connection that was expected to be kept alive was closed by the
    server
    Changing session Thread Time from 60 000ms to 2000ms.
    BatapWebService socket closed.
    Can anyone tell me how to fix that it's very annoyin that is closing the connexion and my messages are not
    being received.
    I need to restart the server each time to be able to receive all messages.
    is that a parameter i have to change?
    please help

    What exactly is the application?
    What is giving you the error? Is there a specific Event ID number and Source name?
    I haven't seen a segmentation error in quite some time. The last time I saw one it was due to an app trying to do something on the OS side that the OS didn't like. I believe DEP protected it, but it was long ago and I don't fully remember the details. It
    was a custom written app and the programmers corrected it.
    I'm not a dev, so I can't help with the app itself.
    Here's more on segmentation errors:
    http://en.wikipedia.org/wiki/Segmentation_fault
    If you need assistance with the app itself, I would suggest to post it to MSDN:
    http://social.msdn.microsoft.com/forums/en-US/categories/
    If it's an app written by another language, you can try this:
    Test your web browser for WebSocket support
    http://jimbergman.net/websocket-web-browser-test/
    Ace Fekay
    MVP, MCT, MCSE 2012, MCITP EA & MCTS Windows 2008/R2, Exchange 2013, 2010 EA & 2007, MCSE & MCSA 2003/2000, MCSA Messaging 2003
    Microsoft Certified Trainer
    Microsoft MVP - Directory Services
    Complete List of Technical Blogs: http://www.delawarecountycomputerconsulting.com/technicalblogs.php
    This posting is provided AS-IS with no warranties or guarantees and confers no rights.

Maybe you are looking for

  • G5 + NTSC Monitor

    I want to add an NTSC Monitor to my editing suite (G5 Tower). I am not sure what I need to do this? Do I need a video card? It is an old used model with A/V cables. I have looked at many posts but still am lost. Thanks Vykus

  • Picture in Picture won't display in a preview of movie

    I dragged a PNG file into the timeline and laid it over a background using Picture in Picture. It shows up in a special track with a blue box around it in the timeline. When I move the mouse over it, it previews correctly. If I play a preview with ei

  • URGENT HELP ! Search did not help !

    *URGENT HELP ! Search did not help !* I bought my new iPod classic three days ago and until yesterday it worked OK. Every time I plug iPod to my computer I get message "CONNECTED" and I hear that sound in Windows that is saying that something is conn

  • Deleted files show as ghost or empty files

    I've been clearing out a ton of old files from my MBP and an external Maxtor HD. For some I've used Spring Cleaning and for others I've used Find and deleted from the results. My problem now is that I search and find literally thousands of titles of

  • Need help in writing SP notification Query

    Hi, My purpose of writing a query is to restrict a user to add journal entry in case account code lies in Expense Drawer and Cost Center Code is not in user define range. Please help me on this:- IF (@object_type = '30' AND (@transaction_type = 'A' O