• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting dateformat compatible to oracle date

 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I want to convert 'yyyymmddhh24miss.ff3' ( the same format we find in log4j file timstamp), in normal date format and want to insert as date in Oracle database. But I could not find any way to do that even SimpleDateFormat is not helping.

Could you please help me out?

Thanks in advance.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15452
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In what form do you have the date in your application? If you have it as a Date object, then you don't need to convert it to a String at all to insert it in the database.

How are you inserting it in the database; using JDBC calls? If you have for example a PreparedStatement, you can use setDate() or setTimestamp() on it. Note that these methods require a java.sql.Date and java.sql.Timestamp object as input. If you have the date as a java.util.Date, then you can easily convert it to one of those:
 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply Jesper.

I am trying to extract data from logs and inserting that data into database. The format of data is



I am trying to insert each line record into table, using SQL Loader. I am not able to insert the date format (yyyyddmmhh24miss.ff3) in database using SQL Loader. I know it could be an easy task in Java.

Could you please put some suggestion on this?

Thanks in advance !

 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SimpleDateFormat seems like the best way to handle this, at least as far as getting a Date object. Can you show us what you've tried with that.? In what way is it not helpful?
 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:SimpleDateFormat seems like the best way to handle this, at least as far as getting a Date object. Can you show us what you've tried with that.? In what way is it not helpful?


Doesn't seem to be working for this as well, just trying the following format



but it throwing IllegalArgumentException.
 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:SimpleDateFormat seems like the best way to handle this, at least as far as getting a Date object. Can you show us what you've tried with that.? In what way is it not helpful?


Doesn't seem to be working for this as well, just trying the following format



It is working for me. Tons of Thanks for all the people who supported me for this.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait, is it working or not? Your last two posts seem to contradict each other. Regardless, I'm pretty sure you need to look at the JavaDoc API for SimpleDateFormat, to figure out wxactly what format string you should be using. Pay particular attention to the case of each letter: 'y' is not the same as 'Y', and 'm' is not the same as 'M'.
 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:Wait, is it working or not? Your last two posts seem to contradict each other. Regardless, I'm pretty sure you need to look at the JavaDoc API for SimpleDateFormat, to figure out wxactly what format string you should be using. Pay particular attention to the case of each letter: 'y' is not the same as 'Y', and 'm' is not the same as 'M'.

It is working for me .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic