首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

ibatis菜鸟遇到的有关问题及解决方法

2012-11-11 
ibatis初学者遇到的问题及解决办法昨日遇到两个问题1)com.ibatis.sqlmap.client.SqlMapException: There i

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]

热点排行