com.ibm.db2.jcc.c.SqlException: The syntax of the string representation of a datetime value is incorrect

StackOverflow https://stackoverflow.com/questions/8676721

  •  09-04-2021
  •  | 
  •  

Frage

I'm getting this exception:

com.ibm.db2.jcc.c.SqlException: The syntax of the string representation of a datetime value is incorrect

while trying to apply java.sql.Date in the format yyyy-mm-DD as the value 2011-12-28 in the Java Code.

War es hilfreich?

Lösung

Try to use PreparedStatement.setDate() method.

For instance,

String date="2011-12-28";
PreparedStatement ps=con.prepareStatement("INSERT INTO Table1 (Col1) VALUES (?)");
ps.setDate(1,java.sql.Date.valueOf(date));
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top