初学IBATIS时,出现的错误。
异常:
java.sql.SQLException: Select statements cannot be executed as an update. at com.ibatis.sqlmap.engine.mapping.statement.SelectStatement.executeUpdate(SelectStatement.java:31) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:447) at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82) at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.insert(SqlMapClientImpl.java:59) at com.ecp.ibatis.main.Test.addPerson(Test.java:46) at com.ecp.ibatis.main.Test.main(Test.java:60) Exception in thread "main"
person_SqlMap.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="Person">
<resultMap id="person" class="com.ecp.ibatis.java.Person">
<!--
WARNING - This element is automatically generated by Abator for iBATIS, do not modify.
This element was generated on Fri Mar 20 15:38:16 CST 2009.
-->
<result column="PER_ID" property="perId" jdbcType="NUMERIC"/>
<result column="PER_FIRSTNAME" property="perFirstname" jdbcType="VARCHAR"/>
<result column="PER_LASTNAME" property="perLastname" jdbcType="VARCHAR"/>
<result column="PER_BIRTHDAY" property="perBirthday" jdbcType="TIMESTAMP"/>
<result column="PER_WEIGTH_KG" property="perWeigthKg" jdbcType="NUMERIC"/>
<result column="PER_HEIGHT_M" property="perHeightM" jdbcType="NUMERIC"/>
</resultMap>
<select id="getPerson" resultMap="person" parameterClass="java.lang.Integer">
<!--
WARNING - This element is automatically generated by Abator for iBATIS, do not modify.
This element was generated on Fri Mar 20 15:38:16 CST 2009.
-->
select PER_ID, PER_FIRSTNAME, PER_LASTNAME, PER_BIRTHDAY, PER_WEIGTH_KG, PER_HEIGHT_M
from Person
where PER_ID = #perId:NUMERIC#
</select>
<select id="addPerson" resultClass="java.lang.Integer" parameterClass="com.ecp.ibatis.java.Person"> insert into Person values(#perId,#perFirstname,#perLastname,#perBirthday,#perWeigthKg,#perHeightM) </select>
</sqlMap>
原因:
是因为在xml文件中,配置的文件有误码,我所要做的操作是往数据库中插入一条记录。
却在配置中配置 <select>
因此产生此错误.
解决办法。把select 改成 insert.