try { if (stmt != null) stmt.close(); if (conn != null) conn.close(); } catch (Exception ignore) { } throw new RemoteException("Unable to print Item description: " +e);
  public String getBuyNowForm(Integer itemId, String username, String password) throws RemoteException  {    int userId = -1;    StringBuffer html = new StringBuffer();    PreparedStatement stmt = null;    ResultSet rs           = null;    Connection conn        = null;    // Authenticate the user who want to comment      if ((username != null && username !="") || (password != null && password !=""))      {        SB_AuthHome authHome = null;        SB_Auth auth = null;        try         {          authHome = (SB_AuthHome)PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/ejb/SB_Auth"), SB_AuthHome.class);          auth = authHome.create();        }         catch (Exception e)        {          throw new RemoteException("Cannot lookup SB_Auth: " +e);        }        try         {          userId = auth.authenticate(username, password);        }         catch (Exception e)        {          throw new RemoteException("Authentication failed: " +e);        }        if (userId == -1)        {           html.append(" You don't have an account on RUBiS!<br>You have to register first.<br>");           return html.toString();        }      }      // Try to find the Item corresponding to the Item ID      String itemName = null, description = null;      String startDate = null, endDate = null, sellerName = null;      int quantity = 0, sellerId = -1;      float buyNow = 0;      try      {        conn = dataSource.getConnection();        stmt = conn.prepareStatement("SELECT * FROM items WHERE id=?");        stmt.setInt(1, itemId.intValue());        rs = stmt.executeQuery();        if (rs.first())        {          itemName = rs.getString("name");          description = rs.getString("description");          startDate = rs.getString("start_date");          endDate = rs.getString("end_date");          buyNow = rs.getFloat("buy_now");          quantity = rs.getInt("quantity");          sellerId = rs.getInt("seller");        }        try        {          stmt = conn.prepareStatement("SELECT nickname FROM users WHERE id=?");          stmt.setInt(1, sellerId);          ResultSet srs = stmt.executeQuery();          if (srs.first())          {            sellerName = srs.getString("nickname");          }        }        catch (SQLException s)        {          try          {            if (stmt != null) stmt.close();            if (conn != null) conn.close();          }          catch (Exception ignore)          {          }          throw new RemoteException("Failed to execute Query for seller: " +s);        }      }      catch (Exception e)      {        try        {          if (stmt != null) stmt.close();          if (conn != null) conn.close();        }        catch (Exception ignore)        {        }        throw new RemoteException("Failed to execute Query for item: " +e);      }      // Display the form for buying the item      html.append("<TABLE width=\"100%\" bgcolor=\"#CCCCFF\">\n<TR><TD align=\"center\" width=\"100%\"><FONT size=\"4\" color=\"#000000\"><B>You are ready to buy this item: "+itemName+"</B></FONT></TD></TR>\n</TABLE><p>\n");      try      {        if (stmt != null) stmt.close();        if (conn != null) conn.close();        html.append(printItemDescriptionToBuyNow(itemId.intValue(), itemName, description, buyNow, quantity, sellerId, sellerName, startDate, endDate, userId));      }      catch (Exception e)      {        try        {          if (stmt != null) stmt.close();          if (conn != null) conn.close();        }        catch (Exception ignore)        {        }        throw new RemoteException("Unable to print Item description: " +e);      }      return html.toString();  }