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.