读书人

生手使用ibatis出错:Element type quot;S

发布时间: 2013-04-05 10:24:33 作者: rapoo

新手使用ibatis出错:Element type "SqlMapConfig" must be declared.
各路英雄好汉,江湖救急:刚接触iBatis(工程导入了mybatis-2.3.5.jar,mySQL 驱动包)

SqlMapConfig.xml 文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE SqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<SqlMapConfig>
<properties resource="SqlMap.properties"/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property value="${driver}" name="JDBC.Driver"/>
<property value="${url}" name="JDBC.ConnectionURL"/>
<property value="${username}" name="JDBC.Username"/>
<property value="${password}" name="JDBC.Password"/>
</dataSource>
</transactionManager>
<SqlMap resource="Student.xml"/>
</SqlMapConfig>



student.xml 文件内容如下 :


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap>

<typeAlias alias="Student" type="myIbatis.Student"/>

<resultMap id="StudentResult" class="Student">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="sex" column="sex"/>
<result property="major" column="major"/>
<result property="birthday" column="birthday"/>
</resultMap>

<select id="selectAllStudent" resultClass="Student">
select * from student_table
</select>

</sqlMap>

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<Student> queryAllStudent() {
List<Student> studentList = null;
try {
studentList = sqlMapClient.queryForList("selectAllStudent");
} catch (SQLException e) {
e.printStackTrace();
}
return studentList ;


}


public List<Student> queryselectStudentByName(String name) {
// TODO Auto-generated method stub
return null;
}


public static void main(String[] args) {
StudentDao studentDao = new StudentDaoImpl();
studentDao.queryAllStudent();

}

}


运行这个 main 方法时报错:Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: org.xml.sax.SAXParseException: Element type "SqlMapConfig" must be declared.


请各位高手帮忙指教一下,感激万分!感激万分!感激万分
[解决办法]
http://blog.csdn.net/zhongweijian/archive/2009/10/10/4651329.aspx

解析xml时出错了
[解决办法]
推荐你看一下iBatis最简单的入门吧:http://www.cppblog.com/biao/archive/2010/10/24/131051.html

每一步写得都很清楚
[解决办法]
view plaincopy to clipboardprint?
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">


改为

view plaincopy to clipboardprint?
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">


------------------------------------------

我没用过iBatis,不知道该过之后行不行


读书人网 >J2EE开发

热点推荐