我正在尝试使用MyBatis更新数据库行。在使用POJO类,DataMapper.XML和Mybatis-config.xml配置MyBatis项目后,我无法更新数据库。需要调试异常的帮助
以下是例外,
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='revision', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #7 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Invalid column index
### The error may involve com.load.mappers.DataMapper.insertCADRelease-Inline
### The error occurred while setting parameters
### SQL: UPDATE XXXX_LOGS SET STATE=?, RELEASEDATE=TO_DATE(?,'MM/DD/YYYY HH12:MI:SS AM'), ORIGINATED=TO_DATE('?','MM/DD/YYYY HH12:MI:SS AM'), MODIFIED=TO_DATE(?,'MM/DD/YYYY HH12:MI:SS AM') where TYPE=? AND NAME=? AND REVISION=?
### Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='revision', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}.
遵循DataMapper.XML和POJO类中的更新定义
<update id="insertXXXX" parameterType="XXXXUpdate">
UPDATE XXXX_LOGS
SET STATE=#{state},
RELEASEDATE=TO_DATE(#{releasedate},'MM/DD/YYYY HH12:MI:SS AM'),
ORIGINATED=TO_DATE('#{originated}','MM/DD/YYYY HH12:MI:SS AM'),
MODIFIED=TO_DATE(#{modified},'MM/DD/YYYY HH12:MI:SS AM')
where
TYPE=#{type}
AND
NAME=#{name}
AND
REVISION=#{revision}
</update>
用于设置对象值的POJO类
public class XXXXUpdate
{
private String state,
releasedate,
originated,
modified,
type,
name,
revision;
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getReleasedate() {
return releasedate;
}
public void setReleasedate(String releasedate) {
this.releasedate = releasedate;
}
public String getOriginated() {
return originated;
}
public void setOriginated(String originated) {
this.originated = originated;
}
public String getModified() {
return modified;
}
public void setModified(String modified) {
this.modified = modified;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRevision() {
return revision;
}
public void setRevision(String revision) {
this.revision = revision;
}
}
mybatig-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="jdbc.properties"/>
<typeAliases>
<typeAlias type="com.load.objects.XXXXUpdate" alias="XXXXUpdate"></typeAlias>
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="DataMapper.xml"/>
</mappers>
</configuration>
请提供有关调试错误的帮助。 提前谢谢。
答案 0 :(得分:0)
删除 originated 参数周围的引号:
ORIGINATED = TO_DATE(&#39;#{originated}&#39; ,&#39; MM / DD / YYYY HH12:MI:SS AM&#39;),