Search code examples
javadb2sqldatetime

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


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.


Solution

  • 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));