2 回答
TA贡献1725条经验 获得超7个赞
例:arrayList中存在一些people对象1.首先要在数据库中建立相应的java对象和数组,如:/*和java对象对应的数据库对象*/CREATETYPEpeopleOracleObjectASOBJECT( peopleOracleIDNUMBER(8), nameOraclevarchar(50), ageOracleNumber(3))/数据库中的arrayCREATETYPEpeople_Oracle_LISTASVARRAY(500)OFpeopleOracle;/2.将java中的arrayList转化privatestaticARRAYgetOracleArray(Connectioncon,StringOraclelist,ArrayListobjlist)throwsException{ ARRAYlist=null; if(objlist!=null&&objlist.size()>0){ StructDescriptorstructdesc=newStructDescriptor( "peopleOracleObject",con); STRUCT[]structs=newSTRUCT[objlist.size()]; Object[]result=newObject[0]; for(inti=0;i<objlist.size();i){ result=newObject[2]; result[0]=newLong(((people)(objlist.get(i))).getPeopleID()); result[1]=newLong(((people)(objlist.get(i))).getPeopleName()); result[2]=newLong(((people)(objlist.get(i))).getPeopleAge()); structs=newSTRUCT(structdesc,con,result);}ArrayDescriptordesc=ArrayDescriptor.createDescriptor(Oraclelist, con);list=newARRAY(desc,con,structs);}else{ ArrayDescriptordesc=ArrayDescriptor.createDescriptor(Oraclelist,con); STRUCT[]structs=newSTRUCT[0]; list=newARRAY(desc,con,structs);}returnlist;}//function3./*把转换后的数组加到存储过程中*/publicstaticintupdateADInfo(ArrayListpeoleList,intID){Connectioncon=null;CallableStatementstmt=null;intbackVal; try{ con=pool.getConnection(); if(con!=null){ stmt=con.prepareCall("{callupdatePeople(?,?,?)}"); ARRAYadArray=getOracleArray(con,"people_Oracle_LIST", peoleList); ((OracleCallableStatement)stmt).setARRAY(1,adArray); stmt.setInt(2,ID); stmt.registerOutParameter(3,java.sql.Types.INTEGER); stmt.execute();}else{ backVal=1;}}catch(Exceptione){ e.printStackTrace();}finally{pool.freeDBResource(con,stmt,null);} returnbackVal;}4.存储过程中调用CREATEORREPLACEPROCEDURENAD_SP_CreateWebCostToAd(p_peopleArrayINpeople_Oracle_LIST,p_IDINnumber,p_outOUTVARCHAR2)ASVpeopleIDnumber(8):=0;VpeopleNamevarchar(50):=0;Vagenumber(3):=0;beginfori1...p_peopleArray.countloop peopleObj:=p_peopleArray(i); VpeopleID:=peopleObj.peopleOracleID; VpeopleName:=peopleObj.nameOracle; Vage:=peopleObj.ageOracle;................. endloop; commit;EXCEPTIONWHENOTHERSTHENp_out:=’-1’||SQLERRM;ROLLBACK;END;/SHOWERRORS
添加回答
举报