Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mybatis calls oracle stored procedure

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Stored Procedures with Input and Output Parameters

Oracle stored procedure part code:

create or replace procedure PT_copy_Shipment_One_Data(

oldShipmentId in varchar ,

servprovGid in varchar ,

insertUser in varchar,

resultShipmentId out varchar

)is

newShipmentGid varchar2(50 );

newShipmentXid varchar2(50 );

newShipmentTypeGid varchar2(50 );

begin

--PLSQL body executed

commit;--commit something

Exception

When others then

Rollback;

end PT_copy_Shipment_One_Data;

Xml configuration for mybatis

Note: Although there is a return value, do not need to know the return parameter class, see the java code example below for details.

{call PT_copy_Shipment_One_Data(

#{oldShipmentId,mode=IN,jdbcType=VARCHAR},

#{servprovGid,mode=IN,jdbcType=VARCHAR},

#{insertUser,mode=IN,jdbcType=VARCHAR},

#{resultShipmentId,mode=OUT,jdbcType=VARCHAR}

)}

]]>

Dao or Service Code

Map parasMap = new HashMap();

parasMap.put("oldShipmentId", para.get( "shipmentId"));

parasMap.put( "servprovGid", para.get("skdw"));//attr12

parasMap.put( "insertUser", Users.getCurrent());

parasMap.put( "resultShipmentId", "" );

//call stored procedure

this.getSqlSessionTemplate().

selectOne("com.otm.app.entity.pojo.ShipmentCost.callCoptShipment",parasMap);

parasMap.put("shipmentId", parasMap.get("resultShipmentId" ));

return parasMap;

For example, if the code is superscript red, there is no need to set the return parameter in mybatis, and then there is no need to accept the return parameter when calling the stored procedure in java. The map parameter will automatically have. This is a strange place.

AC Technical Group No.:50567913

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report