初次学习ibatis...太辛苦..问题搞不定...请帮忙解决一下.....

其它查询都可以,删除都可以.就是增加和修改报错了.

sqlMapConfig.xml是没有问题的.

**********************customer.xml*************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">

<select id="customerAll" resultClass="Customer">
    select id,name,enName,describe
    from customer
</select>

<select id="selectCustomerById" parameterClass="int" resultClass="Customer">
        select id,name,enName,describe
    from customer where id=#id#
</select>

<delete id="deleteCustomer" parameterClass="int">
    delete from customer where id = #id#
</delete>

[color=red][b]<insert id="insertCustomer" parameterClass="Customer">
    insert into customer(id,    name,    enName,     describe)
                values  ("#id#","#name#","#enName#","#describe#")
</insert>

<update id="updateCustomer" parameterClass="Customer">
    update customer set 
        name="#name#",enName="#enName#",describe="#describe#"
    where id="#id#"
</update>[/b]</sqlMap>[/color]

**********************customer.xml*************************

com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in org/gxf/demo/customer.xml.

--- The error occurred while applying a parameter map.

--- Check the insertCustomer-InlineParameterMap.

--- Check the parameter mapping for the 'id' property.

--- Cause: java.sql.SQLException: 无效的列索引
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:107)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:393)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.insert(SqlMapClientImpl.java:58)
at org.gxf.dao.impl.CustomerDaoImpl.addCustomer(CustomerDaoImpl.java:31)
at org.gxf.test.Test.main(Test.java:30)
Caused by: java.sql.SQLException: 无效的列索引
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
at oracle.jdbc.driver.OraclePreparedStatement.setIntInternal(OraclePreparedStatement.java:3970)
at oracle.jdbc.driver.OraclePreparedStatement.setInt(OraclePreparedStatement.java:3961)
at com.ibatis.sqlmap.engine.type.IntegerTypeHandler.setParameter(IntegerTypeHandler.java:30)
at com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameter(ParameterMap.java:166)
at com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameters(ParameterMap.java:126)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:78)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteUpdate(MappedStatement.java:216)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:94)
... 5 more

********************CustomerDaoImpl******************************
public void updateCsutomer(Customer customer) {
try {
sqlMapClient.update("updateCustomer", customer);
} catch (SQLException e) {
e.printStackTrace();
}
}
public void addCustomer(Customer customer) {
try {
System.err.println(sqlMapClient.insert("insertCustomer",customer));
} catch (SQLException e) {
e.printStackTrace();
}
}
*********************test*************************
Customer customer = new Customer();
customer.setId(2);
customer.setName("ibatisName");
customer.setEnName("ibatisEnName");
customer.setDescribe("test_one");
new CustomerDaoImpl().addCustomer(customer);

1个回答

[code="xml"]
values ("#id#","#name#","#enName#","#describe#")
[/code]

这里改成
[code="xml"]
values (#id#,#name#,#enName#,#describe#)
[/code]

不加双引号 请仔细查一下。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问