| 发表于:2007-12-31 01:59:593楼 得分:10 |
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; } java可以这样实现的,dsn_shop是数据源, 慢慢学吧,很好用的! 数据库操作语言学好点就容易了! | | |
|