代码和官方的example是一样的可就是出现
下面问题:Attribute "recource" must be declared for element type "properties".
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> <!-- Configure a built-in transaction manager. If you're using an
app server, you probably want to use its transaction manager
and a managed datasource -->
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost/test"/>
<property name="JDBC.Username" value="root"/>
<property name="JDBC.Password" value="123456"/>
</dataSource>
</transactionManager> <!-- List the SQL Map XML files. They can be loaded from the
classpath, as they are here (com.domain.data...) -->
<sqlMap resource="com/mydomain/data/Account.xml"/>
<!-- List more here...
<sqlMap resource="com/mydomain/data/Order.xml"/>
<sqlMap resource="com/mydomain/data/Documents.xml"/>
--></sqlMapConfig>
Account.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 namespace="Account"> <!-- Use type aliases to avoid typing the full classname every time. -->
<typeAlias alias="Account" type="com.mydomain.domain.Account"/> <!-- Result maps describe the mapping between the columns returned
from a query, and the class properties. A result map isn't
necessary if the columns (or aliases) match to the properties
exactly. --> <resultMap id="AccountResult" class="Account">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
</resultMap> <!-- Select with no parameters using the result map for Account class. -->
<select id="selectAllAccounts" resultMap="AccountResult">
select * from student
</select></sqlMap>高手帮忙看看!到底是什么原因啊?
下面问题:Attribute "recource" must be declared for element type "properties".
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> <!-- Configure a built-in transaction manager. If you're using an
app server, you probably want to use its transaction manager
and a managed datasource -->
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost/test"/>
<property name="JDBC.Username" value="root"/>
<property name="JDBC.Password" value="123456"/>
</dataSource>
</transactionManager> <!-- List the SQL Map XML files. They can be loaded from the
classpath, as they are here (com.domain.data...) -->
<sqlMap resource="com/mydomain/data/Account.xml"/>
<!-- List more here...
<sqlMap resource="com/mydomain/data/Order.xml"/>
<sqlMap resource="com/mydomain/data/Documents.xml"/>
--></sqlMapConfig>
Account.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 namespace="Account"> <!-- Use type aliases to avoid typing the full classname every time. -->
<typeAlias alias="Account" type="com.mydomain.domain.Account"/> <!-- Result maps describe the mapping between the columns returned
from a query, and the class properties. A result map isn't
necessary if the columns (or aliases) match to the properties
exactly. --> <resultMap id="AccountResult" class="Account">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
</resultMap> <!-- Select with no parameters using the result map for Account class. -->
<select id="selectAllAccounts" resultMap="AccountResult">
select * from student
</select></sqlMap>高手帮忙看看!到底是什么原因啊?
解决方案 »
- jsp 和servlet的问题
- 同一个项目中用不同版本jdk的问题??急急急
- 静态模块加载文件出错
- 求在JBUILDER2007中开发,布署一个简单EJB的实例?
- 帮我推荐几本SSH经典的书
- Action jsp页面传中文??
- 为何引入了org.dom4j.io.SAXReader,但在实例化时报错:java.lang.NoClassDefFoundError: org/dom4j/io/SAXReader?
- 下面是我看的一段代码,可是我大体意思我懂了,里面具体的实现细节还不是很懂,希望高手解答。
- 请高手帮忙,问题描述如下:我想用ant来产生(javadoc)文档,但是报错说内存不足。请增加内存……(谢谢)
- (80分)如何把JAVA程序制作成安装程序???
- Spring配置的scope="prototype"没起作用吗
- jsp 中的路径问题
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:49)
at com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)
at test.IStudentDAOImpl.<init>(IStudentDAOImpl.java:17)
at test.IStudentDAOImpl.main(IStudentDAOImpl.java:69)
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: org.xml.sax.SAXParseException: Attribute "recource" must be declared for element type "properties".
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:46)
... 3 more
Caused by: org.xml.sax.SAXParseException: Attribute "recource" must be declared for element type "properties".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at com.ibatis.common.xml.NodeletParser.createDocument(NodeletParser.java:157)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:50)
... 4 more
思路:
1、定位问题在哪里?将 <sqlMap resource="com/mydomain/data/Account.xml"/> 注释掉看看
2、如果没有问题,那么将注释去掉,在将 Account.xml 的内容不部分去掉,排除
3、这样进一步定位问题
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.ibatis.common.resources.Resources;
import com.mydomain.domain.Account;import java.io.Reader;
import java.io.IOException;
import java.util.List;
import java.sql.SQLException;import test.IStudentDAO;
import test.IStudentDAOImpl;
import test.Student;/**
* This is not a best practices class. It's just an example to give you an idea
* of how iBATIS works. For a more complete example, see JPetStore 5.0 at
* http://www.ibatis.com.
*/
public class SimpleExample { /**
* SqlMapClient instances are thread safe, so you only need one. In this
* case, we'll use a static singleton. So sue me. ;-)
*/
private static SqlMapClient sqlMapper; /**
* It's not a good idea to put code that can fail in a class initializer,
* but for sake of argument, here's how you configure an SQL Map.
*/
static {
try {
Reader reader = Resources
.getResourceAsReader("com/mydomain/data/SqlMapConfig.xml");
sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
reader.close();
} catch (IOException e) {
// Fail fast.
throw new RuntimeException(
"Something bad happened while building the SqlMapClient instance."
+ e, e);
}
} @SuppressWarnings("unchecked")
public static List selectAllAccounts() throws SQLException {
return sqlMapper.queryForList("selectAllAccounts");
} public static Account selectAccountById(int id) throws SQLException {
return (Account) sqlMapper.queryForObject("selectAccountById", id);
} public static void insertAccount(Account account) throws SQLException {
sqlMapper.insert("insertAccount", account);
} public static void updateAccount(Account account) throws SQLException {
sqlMapper.update("updateAccount", account);
} public static void deleteAccount(int id) throws SQLException {
sqlMapper.delete("deleteAccount", id);
}
public static void main(String[] args)
{
try {
IStudentDAO dao=new IStudentDAOImpl();
for(Student student:dao.queryallstudent())
{
System.err.println(student);
}
} catch (Exception e) {
e.printStackTrace();
}
}}
后面加一行
<properties resource="sqlMapconfig.properties" />同目录 建立一个 sqlMapconfig.properties,空白的也行,这个是可以用来配置 数据库信息的