I have two groovy scripts that make respectively an insert and an update on a oracle table that has a string column and two timestamp columns, created like as follows:
CREATE TABLE sn_token (
"token" varchar2(500 char) NOT NULL,
created_at timestamp NOT NULL,
updated_at timestamp,
PRIMARY KEY ("token")
);
In the first groovy script I make an insert on this table using this groovy code snippet (I omit the snippet code that makes the connection to the database):
import java.util.Date;
import org.joda.time.DateTime;
DateTime now = DateTime.now()
Date date = now.toDate()
def createdTimestamp = date.toTimestamp()
def map = [token : "myToken", created_at : createdTimestamp]
sql.execute "INSERT INTO sn_token (\"token\", created_at) VALUES ($map.token, $map.created_at)"
and all it's ok, and the timestamp that is stored, logged into console, is:
2018-07-20 09:38:24.191
In the second script I make an update on the same row, using this groovy code snippet (I omit the snippet code that makes the connection to the database):
import java.util.Date;
import org.joda.time.DateTime;
DateTime now = DateTime.now()
Date date = now.toDate()
def updatedTimestamp = date.toTimestamp()
def myToken = "myToken"
sql.execute 'UPDATE sn_token SET updated_at = \'' + updatedTimestamp + '\' WHERE "token" = \'' + myToken + '\''
The value of the updatedTimestamp variable logged into console is:
2018-07-20 09:40:44.706
and the query that is generated is:
UPDATE sn_token SET updated_at = '2018-07-20 09:40:44.706' WHERE "token" = "myToken"
Although the two timestamp variables have the same format, the update sql returns the error
ORA-01843: not a valid month
and I don't understand why..
Can someone help me to solve this problem?
Thanks