Friday, 15 January 2010

java - SQL Procedure call from mybatis -



java - SQL Procedure call from mybatis -

all, trying phone call sql procedure java user mybatis, getting "java.sql.sqlexception: missing in or out parameter @ index:: 1". googling doesnt give me right answers. below code wrote. using mybatis first time, can please guide me.

mepper.xml :---

<select id="addhardwarelist" statementtype="callable" parametertype="java.util.hashmap"> { phone call p_hw_sw_crud.save_hardware_inventory( #{pdatain,javatype=object,jdbctype=array,jdbctypename=tab_idesk_hw_info,mode=in,typehandler=com.tristar.idesk.mybatis.mapper.hardwareinventoryhandler} #{pmsgcodeout,javatype=long,jdbctype=decimal,mode=out} ) } </select>

here setup map --

public void addupdateinventory(jsonnode jsonnode) { map<string, ?> inventorymap = getmapfromjsonaddupdate(jsonnode); hashmap<string,object> returnmap = new hashmap<string,object>(); long perrodcodeout = null; string perrormsg = null; returnmap.put("pdatain", (list<hardwareinventorybean>) inventorymap.get("beanhardwarelist")); returnmap.put("perrorcodeout", perrodcodeout); //returnmap.put("perrodmsgout", perrormsg); hardwareinventorymapper.addhardwarelist(returnmap); }

i implemented custom type handler map java bean attributes oracletype object.

public class hardwareinventoryhandler implements typehandler{ public void setparameter(preparedstatement ps, int i, object parameter, jdbctype jdbctype) throws sqlexception { try{ //new recloaderservice().getjsonobj("rec_icast_claimant_info", "tab_icast_claimant_info", jsonobject, i, ps); system.out.println(parameter); list<hardwareinventorybean> hwinventorylist = (list<hardwareinventorybean>) parameter; system.out.println("parameter here --"+parameter); structdescriptor structdescriptor = structdescriptor.createdescriptor(inventoryconstants.hw_db_rec_type_name, ps.getconnection()); struct[] structs = null; structs = new struct[hwinventorylist.size()]; (int index = 0; index < hwinventorylist.size(); index++) { hardwareinventorybean hwinventorybean = hwinventorylist.get(index); object[] params = new object[12]; params[0] = hwinventorybean.gethwid(); params[1] = hwinventorybean.gethwtypeid(); params[2] = hwinventorybean.gethwmodelid(); params[3] = hwinventorybean.getassetid(); params[4] = hwinventorybean.getdatereceived(); params[5] = hwinventorybean.gethwprice(); params[6] = hwinventorybean.gethwstatus(); params[7] = hwinventorybean.gethwwarranty(); params[8] = hwinventorybean.getcreatedby(); params[9] = hwinventorybean.getcreateddate(); params[10] = hwinventorybean.getmodifiedby(); params[11] = hwinventorybean.getmodifieddate(); system.out.println("---------> " +hwinventorybean.gethwid()); struct struct = new struct(structdescriptor, ps.getconnection(), params); structs[index] = struct; } arraydescriptor desc = arraydescriptor.createdescriptor(inventoryconstants.hw_db_teb_type_name, ps.getconnection()); array oraclearray = new array(desc, ps.getconnection(), structs); ps.setarray(i, oraclearray); } catch(exception e){ e.printstacktrace(); } } public jsonobject getresult(resultset rs, string columnname) throws sqlexception { // todo auto-generated method stub homecoming null; } public jsonobject getresult(resultset rs, int columnindex) throws sqlexception { // todo auto-generated method stub homecoming null; } public jsonobject getresult(callablestatement cs, int columnindex) throws sqlexception { // todo auto-generated method stub homecoming null; } }

mapper interface ----

public void addhardwarelist(hashmap<string, object> returnmap);

my sql procedure code :-

create or replace bundle body p_hw_sw_crud -- body procedure save_hardware_inventory (hw in tab_idesk_hw_info, nu out number) error_code number(10); error_desc varchar2(200); begin nu := 10; in 1 .. hw.count loop if(hw(i).hw_id <> 0) insert idesk_hw_inventory values (idesk_hw_inventory_seq.nextval, hw(i).hwtypeid , hw(i).hwmodelid,hw(i).assetid , hw(i).datereceived , hw(i).hwprice ,hw(i).hwstatus , hw(i).hwwarrenty , hw(i).createdby , sysdate,hw(i).modifiedby, sysdate); else update idesk_hw_inventory set hw_type_id=hw(i).hwtypeid,hw_model_id=hw(i).hwmodelid,asset_id=hw(i).assetid,date_received=hw(i).datereceived,hw_price=hw(i).hwprice,hw_status=hw(i).hwstatus,hw_warrenty=hw(i).hwwarrenty,modified_by=hw(i).modifiedby,modified_date=sysdate hw_id=hw(i).hw_id; end if; end loop; exception when others rollback; error_code := sqlcode; error_desc := sqlerrm; end save_hardware_inventory ; procedure save_software_inventory (sw in tab_idesk_sw_info ) error_code number(10); error_desc varchar2(200); begin in 1 .. sw.count loop if(sw(i).sw_id <> 0) insert idesk_sw_inventory values (idesk_sw_inventory_seq.nextval, sw(i).sw_vendor_id , sw(i).sw_version_title,sw(i).quantity , sw(i).price , sw(i).contract_acount_num ,sw(i).sw_status , sw(i).created_by ,sysdate, sw(i).modified_by , sysdate); else update idesk_sw_inventory set sw_vendor_id=sw(i).sw_vendor_id,sw_version_title=sw(i).sw_version_title,quantity=sw(i).quantity,price=sw(i).price,contract_acount_num=sw(i).contract_acount_num,sw_status=sw(i).sw_status,modified_by=sw(i).modified_by,modified_date=sysdate sw_id=sw(i).sw_id; end if; end loop; exception when others rollback; error_code := sqlcode; error_desc := sqlerrm; end save_software_inventory ; end p_hw_sw_crud ;

believe need callablestatement (which way subclass of preparedstatement) , need utilize 'registeroutparameter'.

see if this example helps.

java oracle hibernate mybatis ibatis

No comments:

Post a Comment