2 Replies Latest reply on Jul 11, 2005 3:29 AM by Venkitachalam Subramanian

    Connection Closed

    Venkitachalam Subramanian Newbie

      I get the follwoing error when trying to access session EJB from jsp

      " Connection handle has been closed and is unusable "

      My EJB would look like

      public class userReport implements SessionBean
      {

      private Connection con = null;

      public void makeConnection() throws RemoteException,NamingException,SQLException
      {
      try
      {
      InitialContext ic =null;
      DataSource ds = null;
      con = null;
      ic = new InitialContext();
      ds = (DataSource) ic.lookup("java:jdbc/SybaseDB");
      con = ds.getConnection();
      }
      catch(Exception e)
      {
      con.close();
      System.out.println(e);
      }
      finally
      {
      con.close();
      }
      }
      .........
      ..........
      public int insertAccounts(String[] reportParams) throws RemoteException,NamingException,SQLException
      {
      Vector accVector = new Vector();
      try
      {
      PreparedStatement ls_stmt = null;
      int result = 0;
      ls_stmt = con.prepareStatement("exec prc_mis_report_accs_ins ?");
      for(int j=0;j< reportParams.length;j++)
      {
      ls_stmt.setString(1,reportParams[j]);
      result = ls_stmt.executeUpdate();
      }
      }
      catch(SQLException e)
      {
      con.close();
      System.out.println(e);
      return 0;
      }
      catch(Exception e)
      {
      con.close();
      System.out.println(e);
      return 0;
      }
      return 1;
      }
      .............
      ...............
      }

      and jsp would be

      objRemote.makeConnection();

      String[] reportParams = request.getParameterValues("income_acc");
      ret_value = objRemote.insertAccounts(reportParams);

      but after makeConnection() I get the error as above.


      Please Help........


      Thanx
      Venki

        • 1. Re: Connection Closed
          Venkitachalam Subramanian Newbie

          I am sorry , the error occurs even when finally section is removed from the Bean class

          thanx
          Venki

          "venkitachalam_s81" wrote:
          I get the follwoing error when trying to access session EJB from jsp

          " Connection handle has been closed and is unusable "

          My EJB would look like

          public class userReport implements SessionBean
          {

          private Connection con = null;

          public void makeConnection() throws RemoteException,NamingException,SQLException
          {
          try
          {
          InitialContext ic =null;
          DataSource ds = null;
          con = null;
          ic = new InitialContext();
          ds = (DataSource) ic.lookup("java:jdbc/SybaseDB");
          con = ds.getConnection();
          }
          catch(Exception e)
          {
          con.close();
          System.out.println(e);
          }
          finally
          {
          con.close();
          }
          }
          .........
          ..........
          public int insertAccounts(String[] reportParams) throws RemoteException,NamingException,SQLException
          {
          Vector accVector = new Vector();
          try
          {
          PreparedStatement ls_stmt = null;
          int result = 0;
          ls_stmt = con.prepareStatement("exec prc_mis_report_accs_ins ?");
          for(int j=0;j< reportParams.length;j++)
          {
          ls_stmt.setString(1,reportParams[j]);
          result = ls_stmt.executeUpdate();
          }
          }
          catch(SQLException e)
          {
          con.close();
          System.out.println(e);
          return 0;
          }
          catch(Exception e)
          {
          con.close();
          System.out.println(e);
          return 0;
          }
          return 1;
          }
          .............
          ...............
          }

          and jsp would be

          objRemote.makeConnection();

          String[] reportParams = request.getParameterValues("income_acc");
          ret_value = objRemote.insertAccounts(reportParams);

          but after makeConnection() I get the error as above.


          Please Help........


          Thanx
          Venki


          • 2. Re: Connection Closed
            Venkitachalam Subramanian Newbie

            dear all,

            I found a solution for the same by changing

            false

            in jbossjca-service.xml to

            true


            if there is any side effect to it , please do reply

            thanx
            Venki