+ 2

How can we insert current date in oracle (data type of colum is Date) by using java Language?

I tried sysdate but it is not working

5th Nov 2019, 6:51 AM
Frozen Pearl
Frozen Pearl - avatar
5 Antworten
+ 2
SYSDATE should work. You can build any date like this in Oracle database : TO_DATE('2019-11-05', 'YYYY-MM-DD') what is your insert sql statement that is failing?
5th Nov 2019, 9:08 AM
Tibor Santa
Tibor Santa - avatar
+ 2
sysdate is an sql keyword. It doesn't exist in Java. So you just put it in the raw sql text and don't substitute with ? sql = "insert into sam.test values(sysdate)" ;
5th Nov 2019, 9:33 AM
Tibor Santa
Tibor Santa - avatar
+ 2
Tibor Santa thank u so much it execute 😄
5th Nov 2019, 11:46 AM
Frozen Pearl
Frozen Pearl - avatar
+ 1
Tibor Santa sql ="insert into sam.test value s(?); pst=(oracle prepared statement)conn.preparestatement(sql); pst.setDate(1,sysdate); sysdate is showing error as:can't find symbol
5th Nov 2019, 9:27 AM
Frozen Pearl
Frozen Pearl - avatar
+ 1
i want automatic time insertion that's why I can't use other method
5th Nov 2019, 9:28 AM
Frozen Pearl
Frozen Pearl - avatar