I have an object that contains a date that I retrieve before I insert into an Oracle database. I am having problems converting the string to a date that oracle likes.
String bd = cd.getBeginDate(); //get date String
bd now contains a value like: 2001-02-03 00:00:00.0 //This format is always the case!!!
So I made a simpleDateFormat like this:
java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S");
Now what I would like to do is put this date into a java.sql.Date object and insert it into Oracle.
I go like this:
java.util.Date bDate = fmt.parse(bd);
long temp = bDate.getTime(); //temp now contrains= 2001-02-03
java.sql.Date beginDate = new java.sql.Date( temp );
System.out.println("update CONTRACT set "+
" BEGIN_DATE = '"+beginDate+"', "+
" END_DATE = '24/MAR/2002', "+
" WHERE ID = '"+cd.getId()+"' ");
When running it I get this...
update CONTRACT set BEGIN_DATE = '2001-02-03', END_DATE = '24/MAR/2002', WHERE ID = '5'
java.sql.SQLException: ORA-01861: literal does not match format string
As you can see one date is a fixed string. I did that because I can see oracle accepts only a special format of date. How can I make this work to insert my date correctly?