MyBatis calling stored procedures and function in Oracle

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.