Mybaits Using Stored Procedures

Source: Internet
Author: User

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

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.