数据表定义
CREATE TABLE t_user(
id number(10),
name varchar2(20),
sex number(2),
age number(2),
addr varchar2(50),
zipcode varchar2(6));
pojo定义
package com.ibatis.my.domain;
public class User {
public long id;
public String name;
public long sex;
public long age;
public String addr;
public String zipcode;
//这里省略了set get 方法
}
user.xml 定义
<sqlMap namespace="User">
<typeAlias alias="user" type="com.ibatis.my.domain.User" />
<parameterMap id="userParam" class="user">
<parameter property="id" jdbcType="NUMBER" javaType="java.lang.Long"/>
<parameter property="name" jdbcType="VARCHAR" javaType="java.lang.String"/>
<parameter property="sex" jdbcType="NUMBER" javaType="java.lang.Long"/>
<parameter property="age" jdbcType="NUMBER" javaType="java.lang.Long"/>
<parameter property="addr" jdbcType="CLOB" javaType="java.lang.String"/>
<parameter property="zipcode" jdbcType="VARCHAR" javaType="java.lang.String"/>
</parameterMap>
<insert id="insertUser" parameterMap="userParam" >
<![CDATA[
insert into t_user(id, name, sex, age, addr, zipcode)
values (#id#, #name#, #sex#, #age#, #addr#, #zipcode#)
]]>
</insert>
</sqlMap>
不知道为什么在定义insertUser时用parameterClass="user"就可以插入记录,而用parameterMap="userParam" 时就会报错,我仔细检查过userParam中的每一个字符,和数据表的字段名是完全相同。
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in sql/map/user.xml.
--- The error occurred while applying a parameter map.
--- Check the User.userParam.
--- Check the statement (update failed).
--- Cause: java.sql.SQLException: ORA-00911: 无效字符
Caused by: java.sql.SQLException: ORA-00911: 无效字符
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:91)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:442)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:81)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.insert(SqlMapClientImpl.java:58)
at com.ibatis.my.action.Opperates.insertAll(Opperates.java:33)
at com.ibatis.my.action.Opperates.main(Opperates.java:11)
Caused by: java.sql.SQLException: ORA-00911: 无效字符
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1451)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:862)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1846)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1771)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2361)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:422)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:487)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)