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"));
}