資源描述:
《java中QueryRunner類實(shí)現(xiàn)增刪改查詳解.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、JAVA中DBUtils的QueryRunner類實(shí)現(xiàn)增刪改查詳解一.QueryRunner類實(shí)現(xiàn)增刪改????????? ???publicstat(yī)ic voidmain(String[]args)throwsException{//使用自己的工具類,獲取數(shù)據(jù)庫(kù)的連接對(duì)象Connectionconn=?。蛓JDBCUtils.getConnection();//創(chuàng)建QueryRunner類對(duì)象QueryRunner qr=newQueryRunner();Stringsql =”UPDATE gjp_l
2、edgersetmoney=?,ldesc=?wherelid=?”;Object[] params={998,"買鉆石",3};intresult=qr。update(conn,sql,params);System.out.println(result);DbUtils。close(conn);}二。QueryRunner類獲取查詢結(jié)果集ResultSetHandler??1.常用Handler*?ArrayHandler將結(jié)果集第一行轉(zhuǎn)成對(duì)象數(shù)組???? ????????? ??publicstat(yī)i
3、cvoidmain(String[]args)throwsException{???Connectionconn = MyJDBCUtils.getConnection();???String sql=”SELECT*FROMgjp_ledgerwherelid=?”;???//結(jié)果集處理方式,ArrayHandler 第一行轉(zhuǎn)成對(duì)象數(shù)組???QueryRunnerqr =newQueryRunner();? ??Object[]objects= qr.query(conn,?。髊l,newArrayHa
4、ndler(),3);???for(Object obj:objects){? ??System.out。println(obj);???}???}*?ArrayListHandler?qū)⒔Y(jié)果集中的每一行數(shù)據(jù)都轉(zhuǎn)成一個(gè)對(duì)象數(shù)組,再將轉(zhuǎn)成的多個(gè)對(duì)象數(shù)組存放到List中? ?????????????????publicstaticvoid?。韆in(String[]args) throwsException{??????Connectionconn=MyJDBCUtils.getConnection();Str
5、ingsql="SELECT* FROMgjp_ledger”;QueryRunner qr=new QueryRunner();//執(zhí)行query方法,傳遞連接對(duì)象,SQL語(yǔ)句,結(jié)果集處理方式ArrayListHandlerList