How to use Mybaits to invoke database stored procedures in the following order of Oracle case libraries:
1. Create the following stored procedure in the database:
Create or Replace procedure Pro_hello (P_result out VARCHAR2) is Begin SELECT * FROM table name where condition =p_result End |
2. Write the SQL mapping file Mapper.xml:
<select id= "Prohello" statementtype= "callable" > <! [cdata[ {Call Pro_hello (#{passed in, Mode=in (passed in), Jdbctype=varchar (type of Argument)}) ]]> </select> |
3. Writing Java code to call a stored procedure
public class Proceduretest { public static void Main (string[] args) throws IOException { String resource = "Mybatis.cfg.xml"; Reader reader = Resources.getresourceasreader (Resource); Sqlsessionfactory SSF = new Sqlsessionfactorybuilder (). build (reader); sqlsession session = Ssf.opensession (); try { map<string, string> param = new hashmap<string, string> (); Param.put ("P_user_name", "Zhangsan"); String returnvalue = (string) session.selectone ("User.prohello", param); System.out.println ("message=" + param.get ("P_user_name")); System.out.println ("result=" + param.get ("result")); System.out.println ("returnvalue=" + returnvalue); } catch (Exception e) { E.printstacktrace (); } finally { Session.close (); } } } |
Assuming that the number of incoming parameters is multiple,
<parametermap type= "Drvphotolistinfo" id= "Drvphotolistparam" ><parameter property= "Sfzmmc" jdbcType= " varchar "javatype=" java.lang.String "mode=" in "/> <parameter property=" SFZMHM "jdbctype=" varchar "javatype=" Java.lang.String "mode=" in "/> <parameter property=" Dabh "jdbctype=" VARCHAR "javatype=" java.lang.String "mode=" In "/> <parameter property=" daglbm "jdbctype=" VARCHAR "javatype=" java.lang.String "mode=" in "/> <parameter Property= "YWGLBM" jdbctype= "VARCHAR" javatype= "java.lang.String" mode= "in"/> <parameter property= "JBR" jdbctype= "varchar" javatype= "java.lang.String" mode= "in"/> <parameter property= "bodys" jdbctype= "varchar" Javatype= "java.lang.String" mode= "in"/> <parameter property= "ReturnCode" jdbctype= "VARCHAR" javatype= " Java.lang.String "mode=" Out "/> <parameter property=" Returnresult "jdbctype=" VARCHAR "javatype=" Java.lang.String "mode=" Out "/> </parametermap>//method for calling stored procedures <select id=" SavedrvphotolistiNFO "statementtype=" callable "parametermap=" Drvphotolistparam "> {call business. His_drvda_in (?,?,?,?,?,?,?,?,?)} </select> My stored procedure is placed under the assumption that you didn't put it under the package. {Call His_drvda_in (?,?,?,?
,?,?
,?
,?,?)}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Mybaits Using Stored Procedures