ibatis初学者遇到的问题及解决办法
昨日遇到两个问题
1)com.ibatis.sqlmap.client.SqlMapException: There is no statement named getPerson in this SqlMap.
2)at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.endTransaction
第一个问题 useStatementNamespaces="true" 是在调用sqlmap时添加命名前缀(namespace which is defined in sqlMap xml),false为直接引用sqlmap(id)
第二个问题 是没有数据源造成
示例
Person.java
Person.xml/* * Date Developer Description * * * Classname: examples.domain.Test * * Date: 2009-5-12 * * The source code contained in this listing is proprietary to * HLJ POST YITONG INFO-NET CO.,LTD. * * Unauthorized copying, adaptation, distribution, use, or display * is strictly prohibited. * This software is Copyright 2009 HLJ POST YITONG INFO-NET CO.,LTD. */package examples.domain;import java.io.IOException;import java.io.Reader;import java.sql.SQLException;import java.util.Date;import java.util.List;import com.ibatis.common.resources.Resources;import com.ibatis.sqlmap.client.SqlMapClient;import com.ibatis.sqlmap.client.SqlMapClientBuilder;/** * @author Administrator */public class Test { public static void main(String[] args) { String resource = "examples/domain/SqlMapConfigExample.xml"; Reader reader = null; try { reader = Resources.getResourceAsReader(resource); } catch (IOException e) { e.printStackTrace(); } SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader); try { sqlMap.startTransaction(); Person user = new Person(); user.setId(5); user.setFirstName("刘秀"); user.setBirthDate(new Date()); user.setWeightInKilograms(66.5); sqlMap.update("updatePerson", user); System.out.println("good!---------"); Integer personPk = new Integer(5); List list = sqlMap.queryForList ("getPerson", personPk); System.out.println(list.size()); for (int i=0;i<list.size();i++){ Person author=(Person)list.get(i); System.out.println(author.getFirstName()+"\t"+author.getId()); } sqlMap.commitTransaction(); } catch (SQLException ef) { ef.printStackTrace(); } finally { try { sqlMap.endTransaction(); } catch (SQLException ef) { } } } }[size=xx-small][/size]