Ibatis.net use Summary (iv)--IBatis call stored procedure

Source: Internet
Author: User

IBatis Calling stored Procedures

Http://www.cnblogs.com/jeffwongishandsome/archive/2010/01/10/1543219.html

Http://www.cnblogs.com/firstyi/archive/2008/01/25/1053208.html

Stored procedures are broadly divided into two types:

    • Query class stored procedure--select query the stored procedure of the class, not change the stored procedure of database data
    • Update a stored procedure of class stored procedure--update/insert/delete type, change the stored procedure of database data

Ibatis.net call the stored procedure:

1. Query type of stored procedure

Create a query class stored procedure that contains the output parameters.

CREATE PROCEDURE up_getcountbytitle    @title VARCHAR    ,    @total INT out as    BEGIN        With a as (        '%'[email protected]+'%' )                SELECT @total=count (*) from a    END
get the total number of stored procedures

The XML file, if it contains output parameters, output parameter property values, must contain the column property.

<?XML version= "1.0" encoding= "Utf-8"?><Sqlmapnamespace= "article"xmlns= "Http://ibatis.apache.org/mapping"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance">  <alias>    <Typealiasalias= "article"type= "YY. Micronet.model.article,yy. Micronet.model "/>  </alias>  <Resultmaps>    <ResultmapID= "Fullresultmap"class= "article">      <result Property= "Pkarticle"column= "Pk_article"DbType= "VarChar"/>      <result Property= "ArticleTitle"column= "ArticleTitle"DbType= "NVarChar"/>      <result Property= "Articleauthor"column= "Articleauthor"DbType= "NVarChar"/>      <result Property= "Articlecontent"column= "Articlecontent"DbType= "NVarChar"/>      <result Property= "EditTime"column= "EditTime"DbType= "DateTime"/>      <result Property= "Dr"column= "Dr"DbType= "Bit"/>      <result Property= "Ts"column= "Ts"DbType= "DateTime"/>    </Resultmap>    <Parametermaps>      <!--the number and order of parameters in Parametermap are consistent with the Up_getcountbytitle stored procedure -      <ParametermapID= "params"class= "Hashtable">        <parameter Property= "title" />        <parameter Property= "Total"column= "Total"direction= "Output"/>      </Parametermap>    </Parametermaps>  </Resultmaps>  <Statements>    <!--calling a stored procedure of a query type -    <procedureID= "Article_getcountbytitle"Parametermap=""ResultClass= "System.Int32">Up_getcountbytitle</procedure>  </Statements></Sqlmap>
Articlemap.xml

Called in CS

        Public ilist<article> Getcountbytitle (Hashtable ht)        {            String stmtid = "Article_getcountbytitle";            ilist<article> result = sqlmap.queryforlist<article> (Stmtid,  ht);            return result;        }

  

Ibatis.net use Summary (iv)--IBatis call stored procedure

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.