• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Insert date into oracle database

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic