IBATIS SQLMAP API Programming Analysis

Source: Internet
Author: User
Tags config

How is IBATIS sqlmap API programmed? First, when we configure the Sqlmap-config.xml file, we need to parse it, for example:

Java code for IBATIS Sqlmap

public void insert(Person p){
    String xml = "com/Jdnis/ibatis/map/sql-map-config.xml";
    SqlMapClient sqlMap = null;
    try {
        Reader reader = Resources.getResourceAsReader(xml);
        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
        sqlMap.startTransaction();
        sqlMap.insert("insertPerson",p);
        sqlMap.commitTransaction();
        System.out.println("数据插入成功");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        System.out.println("主键 "+p.getId()+" 冲突!无法插入数据");
    }finally{
        try {
            sqlMap.endTransaction();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}   

IBATIS Sqlmap API Programming Batch processing:

Java code

sqlMap.startBatch();
//...execute statements in between
sqlMap.executeBatch();

IBATIS Sqlmap API Programming is explained here, I hope to help you.

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.