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

Connection has already been closed in Java Program

Hi!
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;

    try{
      String str = "";
      dsl = obtiene_ds();  /* get DataSource */
      dbConnProcess = new SqlConnection(dsl);
      Conn = dbConnProcess.setActiveCacheConnection1(); /* get connection */
      cstmt = dbConnProcess.getCallableStatement1(
          "{call sps_catalogo_consulta_ad2(?,?,?)}",
          ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE,Conn);
      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) {}
    }
  }
0
carolastra
Asked:
carolastra
1 Solution
 
rama_krishna580Commented:
Hi,

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.

R.K
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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