File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes converting dateformat compatible to oracle date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "converting dateformat compatible to oracle date" Watch "converting dateformat compatible to oracle date" New topic
Author

converting dateformat compatible to oracle date

Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 231
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.


God Gave Me Nothing I Wanted, He Gave Me Everything I Needed.
OCPJP6
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14347
    
  22

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:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 231
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

Joined: Mar 05, 2008
Posts: 3018
    
  10
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

Joined: Mar 19, 2008
Posts: 231
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

Joined: Mar 19, 2008
Posts: 231
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

Joined: Mar 05, 2008
Posts: 3018
    
  10
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

Joined: Mar 19, 2008
Posts: 231
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 .
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: converting dateformat compatible to oracle date