

////////////////////////////////////////////////////////////
//
// bean  private ޼ҵ
// getConnection(), cleanup(),  id(), log()
//
///////////////////////////////////////////////////////////

  private Connection getConnection()
    throws SQLException
  {
    InitialContext initCtx = null;
    try {
      initCtx = new InitialContext();
      DataSource ds = (javax.sql.DataSource)
        initCtx.lookup("java:comp/env/jdbc/demoPool");
      return ds.getConnection();
    } catch(NamingException ne) {
      log("UNABLE to get a connection from demoPool!");
      log("Please make sure that you have setup the connection pool properly");
      throw new EJBException(ne);
    } finally {
      try {
        if(initCtx != null) initCtx.close();
      } catch(NamingException ne) {
        log("Error closing context: " + ne);
        throw new EJBException(ne);
      }
    }
  }
  
  
    private void cleanup(Connection con, PreparedStatement ps) {
    try {
      if (ps != null) ps.close(); 
    } catch (Exception e) {
      log("Error closing PreparedStatement: "+e);
      throw new EJBException (e);
    }

    try {
      if (con != null) con.close(); 
    } catch (Exception e) {
      log("Error closing Connection: " + e);
      throw new EJBException (e);

    }
  }
    private String id() {
    return "PK = " + (Integer) ctx.getPrimaryKey();
  }
  
    private void log(String s) {
   	System.out.println(s);
  } 
