MyBatis invokes the stored procedure, containing the returned result set, return parameter, and output parameters. __mybatis

Source: Internet
Author: User

Stored procedures:

Use Base_passport

Go

Create proc Yhj_test

@input_a int,

@input_b int,

@output_c int Out

As

Begin

SELECT * from Config.city;

Set @output_c = @input_a * @input_b;

return @input_a + @input_b;

End

Mybats configuration:

<resultmap type= "Java.util.HashMap" id= "Resultmap" >

<result column= "City_key" property= "Citykey" javatype= "Java.lang.Integer" jdbctype= "Integer"/>

<result column= "Province_key" property= "Provincekey" javatype= "Java.lang.Integer" jdbctype= "Integer"/>

<result column= "City_name" property= "CityName" javatype= "java.lang.String" jdbctype= "VARCHAR"/>

</resultMap>

<select id= "Testbyproc" statementtype= "callable" parametertype= "Java.util.HashMap" resultmap= "Resultmap" >

<! [cdata[

{#{d,mode=out,jdbctype=integer}=call Dbo.yhj_test (

#{a,mode=in,jdbctype=integer},

#{b,mode=in,jdbctype=integer},

#{c,mode=out,jdbctype=integer}

)}

]]>

</select>

Java code

map<string, object> parammap = new hashmap<string, object> ();

Parammap.put ("A", 2);

Parammap.put ("B", 3);

List<city> citys = (list<city>) gettemplate (). SelectList (Getnamespaceandmethod ("TestByProc"), ParamMap) ;

return citys;

Through the above code we can get the corresponding result set, return parameters and output parameters. Where the return parameter and output parameters are placed in the incoming Parammap, the results are as follows:

C is the output parameter of the stored procedure, and D is the return parameter.

Things to be aware of:

1, the stored procedure parameters and names are independent, and only the order of the relationship

2, the stored procedure output parameters, can only be obtained through the incoming map

3. The result set returned by the stored procedure can be received directly with the returned map

4, the return result of the stored procedure need to use? =call procname (?,?) The first parameter receives, you need to specify the corresponding mode out type

5, the stored procedure corresponds to the data type is enumerated type, need to use uppercase, such as varchar

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.