加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用PreparedStatementSetter 设置参数跟 表字段类型不匹配出现

发布时间:2020-12-13 18:01:12 所属栏目:百科 来源:网络整理
导读:错误提示 [ INFO 2008-04-08 14:57:42 org.springframework.jdbc.support.SQLErrorCodesFactory - 120 - init ] : SQLErrorCodes loaded: [DB2,HSQL,MS-SQL,MySQL,Oracle,Informix,PostgreSQL,Sybase] [ ERROR 2008-04-08 14:57:42 yourpackagePaht.dao.impl

错误提示
[ INFO 2008-04-08 14:57:42 org.springframework.jdbc.support.SQLErrorCodesFactory - 120 - <init> ] : SQLErrorCodes loaded: [DB2,HSQL,MS-SQL,MySQL,Oracle,Informix,PostgreSQL,Sybase]
[ ERROR 2008-04-08 14:57:42 yourpackagePaht.dao.impl.jdbc.postgresql.OcapDaoImpl - 247 - insertOcap ] : org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO tableName (last_group_date) VALUES (?)]; nested exception is org.postgresql.util.PSQLException: ERROR: column "last_group_date" is of type timestamp with time zone but expression is of type character varying

源码
new PreparedStatementSetter(){
public void setValues(PreparedStatement ps) throws SQLException {
int i=1;
ps.setString(i++,"2008-04-10" );
}

原因

数据库表的类型跟PreparedStatementSetter回调方法内的设置参数不一致。如果用SQL 直接调试

INSERT INTO tableName (last_group_date ) VALUES ("2008-04-10") 在Database直接运行是没有问题的,
但在PreparedStatementSetter 用setString(i,"2008-04-10")是有问题的

正确代码

new PreparedStatementSetter(){ public void setValues(PreparedStatement ps) throws SQLException { int i=1; ps.setDate(i++,ConvertFormula.changeDateStrToTimestamp("2008-04-10") ); }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读