• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1076
  • Last Modified:

Connection has already been closed in Java Program

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) {}
1 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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now