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) {}
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java App Servers

From novice to tech pro — start learning today.