Bernad Ali
Bernad Ali

Reputation: 1729

ORA-01843 Not a Valid Month with Oracle SQL

I'm using a sql statement in my program.

stringBuffer sql=new StringBuffer();
sql.append("insert into customer (id,createddate) ");
sql.append("values (1,");
sql.append("'"+new Timestamp(System.currentTimeMillis())+"'");

String results=jdbcTemplate.update(sql.toString();

when i executed above command,i got this exception nested exception is java.sql.SQLException: ORA-01843: not a valid month

i should bind the current date ,how do i solve this issue.

Thanks.

Upvotes: 0

Views: 5132

Answers (1)

A.B.Cade
A.B.Cade

Reputation: 16905

If you can use the DB's date then use sysdate ie:

stringBuffer sql=new StringBuffer();
sql.append("insert into customer (id,createddate) ");
sql.append("values (1,sysdate)");

Or you can add a to_date to the query:

stringBuffer sql=new StringBuffer();
sql.append("insert into customer (id,createddate) ");
sql.append("values (1,to_date(");
sql.append("'"+<your TimeStamp converted to a String like yyyyMMddHHmmss>+"', 'yyyymmddhh24miss'");

Or use a PreparedStatement as here

Upvotes: 4

Related Questions