one, mybatis call stored procedure
1 Create the following stored procedure in the database
Create or Replace procedure Pro_hello (P_user_name in Varchar2,p_result out VARCHAR2) is
Begin
P_result: = ' Hello, ' | | P_user_name;
End
2 Writing the SQL mapping file Mapper.xml
The callable in StatementType is labeled this SQL as a stored procedure.
ParameterType is the label to pass the parameters, read some information does not write parametertype words by default map. It's better to add clarity.
<select id= "Prohello" parametertype= "Java.util.map" statementtype= "callable" >
{Call Pro_hello (#{uname,mode=in,jdbctype=varchar},#{result,mode=out,jdbctype=varchar})}
</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 ("uname", "Zhangsan");
Param.put ("Result", "");
String returnvalue = (string) session.selectone ("User.prohello", param);
System.out.println ("message=" + param.get ("uname"));
System.out.println ("result=" + param.get ("result"));
System.out.println ("returnvalue=" + returnvalue);
} catch (Exception e) {
E.printstacktrace ();
} finally {
Session.close ();
}
}
}
Second, MyBatis call function
function with a return value, assuming that an Oracle function increases the student's return to a successful or unsuccessful string
<select id= "IsMember" statementtype= "callable" Parametertype= "CN. Studentdto ">
{#{result,mode=out,jdbvtype=varchar} = Call
Addstudent (#{num,mode=in,jdbctype=decimal},#{name,mode=in,jdbctype=varchar},#{rollinyear,mode=in,jdbctype=date },#{age,mode=out,jdbctype=integer})}
</select>
Studentdto requires a string-type result field in addition to the Student information field that appears above.
Original address:
http://chenjc-it.iteye.com/blog/1443432
http://shen84121062.iteye.com/blog/1213857
MyBatis calling stored procedures and function in Oracle