iBATIS SQLMap API編程如何進行呢?首先我們配置好sqlmap-config.xml文件以後,需要對他進行解析,例如:
iBATIS SQLMap的Java代碼
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編程批處理:
Java代碼
sqlMap.startBatch();
//...execute statements in between
sqlMap.executeBatch();
iBATIS SQLMap API編程就講解到這裡,希望對你有所幫助。