关于EJB返回值的最好的解决方案
相信很多人都有如此之困惑,得此解决方法不敢独享,公之于众,以利后来人。
有两种方法:
1、用vector:
| /**
* Finds all EJBeans with a balance greater than a given amount. * Returns an Enumeration of found EJBean primary keys. * * @param balanceGreaterThan double Test Amount * @return Enumeration EJBean Primary Keys * @exception javax.ejb.EJBException * if there is a communications or systems failure */ public Enumeration ejbFindBigAccounts(double balanceGreaterThan) { log("ejbFindBigAccounts (balance > " + balanceGreaterThan + ")"); Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = con.prepareStatement("select id from ejbAccounts where bal ?"); ps.setDouble(1, balanceGreaterThan); ps.executeQuery(); ResultSet rs = ps.getResultSet(); Vector v = new Vector(); String pk; while (rs.next()) { pk = rs.getString(1); v.addElement(pk); return v.elements(); } catch (SQLException sqe) { log("SQLException: " + sqe); throw new EJBException (sqe); } finally { cleanup(con, ps); } } |
- 本文关键词:

