Connection has already been closed in Java Program

Posted on 2006-04-26
Last Modified: 2013-12-10
I have a Java Program and sometimes return the error: Connection has already been closed

The platforms are:

1)       JConnect 5.5.
2)       Driver: Sybase’s Driver (Type 4) Versions: 5.X
(jconn2.jar, com.sybase.jdbc2.jdbc.SybDriver)
3)       Weblogic 8.1 ServicePack 3 y ServicePack5*

The code for obtain the connection in my program:

public QueryResultDTO catalogosSP(int type, int consolidate, String usuario) throws SQLException, Exception{
    CallableStatement cstmt = null;
    SqlConnection dbConnProcess = null;
    Connection Conn = null;
    QueryResultDTO resultQRDTO = null;

      String str = "";
      dsl = obtiene_ds();  /* get DataSource */
      dbConnProcess = new SqlConnection(dsl);
      Conn = dbConnProcess.setActiveCacheConnection1(); /* get connection */
      cstmt = dbConnProcess.getCallableStatement1(
          "{call sps_catalogo_consulta_ad2(?,?,?)}",
      cstmt.setString(1, usuario);
      cstmt.setInt(2, type);
      cstmt.setInt(3, consolidate);
      resultQRDTO = resultado.processResult(cstmt.executeQuery());   /* execute the stored procedure */
      return resultQRDTO;
    }catch (Exception e) {
        throw new RuntimeException("Error al ejecutar catalogosSP() para tipo 11" + e);
    } finally {
      try {
        if(cstmt!=null){cstmt.close(); cstmt = null;}
        if(Conn!=null){Conn.close(); Conn = null;}
      } catch (Exception e) {}
Question by:carolastra
    1 Comment
    LVL 23

    Accepted Solution


    Look for Active Connections before calling
    >>>>> Conn = dbConnProcess.setActiveCacheConnection1(); /* get connection */

    I think before calling this method itself the connection seems to be terminated, thats why you are seeing this kind of error.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
    There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now