主要涉及以下几方面:
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);