saikiran
saikiran

Reputation: 71

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);

Upvotes: 0

Views: 3565

Answers (2)

Vadim
Vadim

Reputation: 4120

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 i.e. incoming date "05-12-2016" string for Oracle "12/05/2016 00:00:00"

Upvotes: 0

CompEng
CompEng

Reputation: 7376

Try this

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

Upvotes: 1

Related Questions