| 发表于:2007-12-31 02:14:391楼 得分:0 |
public vector getallproduct(){ connection con = null; preparedstatement ps = null; resultset rs = null; vector vec = new vector(); productrecordbean prb = null; try{ class.forname("sun.jdbc.odbc.jdbcodbcdriver"); con = drivermanager.getconnection("jdbc:odbc:dsn_shop"); ps = con.preparestatement("select * from table_product"); rs = ps.EXECutequery(); while(rs.next()){ prb = new productrecordbean(); prb.setid( rs.getint("id") ); prb.setname( rs.getstring("name") ); prb.setprice( rs.getdouble("price") ); prb.setquantity( rs.getint("quantity") ); vec.add(prb); } }catch(exception e){ e.printstacktrace(); }finally{ try{ if(rs!=null) rs.close(); if(ps!=null) ps.close(); if(con!=null) con.close(); }catch(exception e){ e.printstacktrace(); } } return vec; } 给你参考下吧, dsn_shop是数据源 | | |
|