• Post Reply Bookmark Topic Watch Topic
  • New Topic

Insert date into oracle database  RSS feed

 
Kiran Er
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a date which is coming from a csv file and date format in csv file is "10-09-2016 12:00:00" (MM-DD-YYYY hh:mm:ss) format.

I got this date into my program as HashMap<String,Object> format as hm.key(). Once i got the value as String updt = (String)hm.get(key); we are getting as Sun Oct 09 12:00:00 PDT 2016.

I want this updt to insert into oracle database. oracle database column is having  this format (10-09-2016 12:00:00).

I am facing parsing exception in the program before inserting into database.


HashMap<String,Object> hm = jrmunixmap.get(i);
System.out.println("Inside update date::"+hm.get(key));
String updt = (String)hm.get(key);
System.out.println("updt : "+updt);

SimpleDateFormat formatter = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");
Date date1 = null;
date1 = (Date)formatter.parse(dateObject.toString());
System.out.println("Update date: "+date1);

sqlDate = new java.sql.Timestamp (date1.getTime());
stmt.setTimestamp (17, sqlDate);


I am getting parsing exception at date1 = (Date)formatter.parse(dateObject.toString()); this line.

Error:

----
updt : Sun Oct 09 12:00:00 PDT 2016
Parse exception : java.text.ParseException: Unparseable date: "Sun Oct 09 12:00:00 PDT 2016"
java.text.ParseException: Unparseable date: "Sun Oct 09 12:00:00 PDT 2016"
------

Please help me
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kiran,
What type is dateObject? If a date type, it might be easier to avoid string parsing.

Assuming you do need to parse, the correct format string for your sample is:


The SimpleDateFormat class lists the characters and what they mean as a reference.
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kiran Er wrote:
I want this updt to insert into oracle database. oracle database column is having  this format (10-09-2016 12:00:00).


Just to note.
A DATE column doesn't have a format as such.
That format is just the default display (and default datatype conversion) format.  It's nothing to do with how it's stored, or how it translates a Date object into a DATE entry.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!