Error using PreparedStatementSetter to set parameter mismatch with table field type

Source: Internet
Author: User
Tags postgresql

Error tips
[INFO 2008-04-08 14:57:42 org.springframework.jdbc.support.sqlerrorcodesfactory-120-<init>]: SQLErrorCodes Lo aded: [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.springframewo Rk.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 ' type timestamp with time zone But expression is of type character varying

Source
New PreparedStatementSetter () {
public void Setvalues (PreparedStatement PS) throws SQLException {
int i=1;
Ps.setstring (i++, "2008-04-10");
}

reason

The type of the database table is inconsistent with the setting parameters within the PreparedStatementSetter callback method. If you are debugging directly with SQL

INSERT into TableName (last_group_date) VALUES ("2008-04-10") running directly in the database is no problem,
But in PreparedStatementSetter with setstring (i, "2008-04-10") is problematic

Correct code

New PreparedStatementSetter () {
public void Setvalues (PreparedStatement PS) throws SQLException {
int i=1;
Ps.setdate (i++, Convertformula.changedatestrtotimestamp ("2008-04-10"));
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.