简体   繁体   中英

insert java date time into Oracle

Oracle date format on server is MM/DD/YYYY HH24:Mi:SS

I would like to insert a variable which contains a date with timestamp into Oracle date column.

I am getting error while inserting date into Oracle "date column ends before format picture ends".

All I want is append specific timestamp to java string date and insert that string/date format into Oracle database

example:

String incoming_date = request.getParameter("insert_date"); //this comes as a string in dd-mon-yyyy format

formatted_incoming_date = incoming_date + " 00:00:01"; //I want to append time factor to above variable with 00:00:01

insert into testtable values(formatted_incoming_date);

Why you try to insert date as a string? It seems like there is an implicit conversion from string to date in Oracle. Can java.sql.Date be used instead?

Anyway, as long as date comes in format dd-mon-yyyy you have to convert it either into java.sql.Date object or in proper for Oracle string representation as MM/DD/YYYY HH24:Mi:SS ie incoming date "05-12-2016" string for Oracle "12/05/2016 00:00:00"

尝试这个

insert into testtable values(TO_DATE (formatted_incoming_date, 'dd-mon-yyyy hh24:mi:ss);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM