1

I am trying to insert into Oracle Database using JDBC prepared statement. Below is the sql that I am trying to insert.

And everytime I get sql exception for below SQL

private static String insertSQL = "INSERT INTO USER_COPY (ID, CREATION_DATE, LAST_MODIFIED_DATE) VALUES ('123456789', TO_TIMESTAMP('2013-02-01 12:37:40.315'), TO_TIMESTAMP('2013-02-01 12:37:40.315'))";

Exception

unrecognized token '(' in values list, expecting ')'

Table Properties

ID is String
CREATION_DATE timestamp
LAST_MODIFIED_DATE timestamp

Anything wrong with my SQL?

4

1 回答 1

1

I wonder if perhaps it's not your timestamp format? This worked for me using TO_TIMESTAMP:

CREATE TABLE USER_COPY (ID int, CREATION_DATE TimeStamp, LAST_MODIFIED_DATE TimeStamp);

INSERT INTO USER_COPY (ID, CREATION_DATE, LAST_MODIFIED_DATE)
VALUES ('123456789',
        TO_TIMESTAMP('2013-02-01 12:37:40.315', 'YYYY-MM-DD HH24:MI:SS.FF'), 
        TO_TIMESTAMP('2013-02-01 12:37:40.315', 'YYYY-MM-DD HH24:MI:SS.FF')
        );

And here is the SQL Fiddle.

Good luck.

于 2013-02-02T06:54:16.120 回答