ibatis 使用

主要涉及以下几方面:

1。sqlmapconfig.xml  类目录下,定义数据源及其资源文件定义

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
  <transactionManager type="JDBC" commitRequired="true">
  <!--
    <dataSource type="JNDI">
      <property name="DataSource" value="jdbc/manage2"/>
    </dataSource>
    -->
      <dataSource type="SIMPLE">
      <property name="JDBC.Driver" value="com.ibm.db2.jcc.DB2Driver"/>
      <property name="JDBC.ConnectionURL" value="jdbc:db2://ip:50001/testdb"/>
      <property name="JDBC.Username" value=?/>
      <property name="JDBC.Password" value=?/>
      <property name="JDBC.DefaultAutoCommit" value="true"/>
      <property name="Pool.MaximumActiveConnections" value="2"/>
      <property name="Pool.MaximumIdleConnections" value="1"/>
      <property name="Pool.TimeToWait" value="500"/>
      </dataSource>
  </transactionManager>
  <sqlMap resource="db2/apply.xml"/>
</sqlMapConfig>

2,定义资源apply.xml文件,sql语句定义处,与类文件同目录

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="User">
  <select id="selectapply" resultClass="db2.Apply">
      select * from SCOTT.CRM_APPLY200609
  </select>
</sqlMap>

3,结果类Apply.class,

public class Apply implements Serializable {
   
    /** Creates a new instance of Apply */
    private String dev_no;

    private String cust_id;

    private String post_flag;

    private int postcust_type;

    private int postcancel_flag;

    public String getDev_no() {
        return dev_no;
    }

    public void setDev_no(String dev_no) {
        this.dev_no = dev_no;
    }

    public String getCust_id() {
        return cust_id;
    }

    public void setCust_id(String cust_id) {
        this.cust_id = cust_id;
    }

    public String getPost_flag() {
        return post_flag;
    }

    public void setPost_flag(String post_flag) {
        this.post_flag = post_flag;
    }

    public int getPostcust_type() {
        return postcust_type;
    }

    public void setPostcust_type(int postcust_type) {
        this.postcust_type = postcust_type;
    }

    public int getPostcancel_flag() {
        return postcancel_flag;
    }

    public void setPostcancel_flag(int postcancel_flag) {
        this.postcancel_flag = postcancel_flag;
    }

}

 

4,添加ibatis库文件

5,ibatis API调用

 private static SqlMapClient sqlMapClinet;reader = Resources.getResourceAsReader(configXML);
            sqlMapClinet = SqlMapClientBuilder.buildSqlMapClient(reader);


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值