当前位置:我的异常网» J2EE » 生手使用ibatis出错:Element type "SqlMapCon
生手使用ibatis出错:Element type "SqlMapConfig" must be declared
www.myexceptions.net 网友分享于:2013-04-06 浏览:168次
新手使用ibatis出错:Element type "SqlMapConfig" must be declared.
各路英雄好汉,江湖救急:刚接触iBatis(工程导入了mybatis-2.3.5.jar,mySQL 驱动包)
SqlMapConfig.xml 文件内容如下:
SqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
student.xml 文件内容如下 :
sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
select * from student_table
SqlMap.properties 文件内容如下 :
driver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost:3306/myIbatisDB"
username="root"
password="fhlu18"
写了一个方法 studentDaoImpl.jva
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;
import myIbatis.Student;
import com.ibatis.sqlmap.client.SqlMapClient;
public class StudentDaoImpl implements StudentDao {
private static SqlMapClient sqlMapClient = null;
static {
try {
Reader reader = com.ibatis.common.resources.Resources.getResourceAsReader("myIbatis/SqlMapConfig.xml");
sqlMapClient = com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(reader);
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public List queryAllStudent() {
List studentList = null;
try {
studentList = sqlMapClient.queryForList("selectAllStudent");
} catch (SQLException e) {
e.printStackTrace();
}
return studentList ;
文章评论