This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Mapping Java Date to an Oracle Date. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Mapping Java Date to an Oracle Date." Watch "Mapping Java Date to an Oracle Date." New topic
Author

Mapping Java Date to an Oracle Date.

Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 588
I get todays date from my java application and add it to my Oracle Database.
I need to add the date in the format '31-OCT-02'
the only string in this format is using the date method toGMTString() toGMTString()
'31-OCT-2002 14:41:24 GMT'
I can parse this string to translate it into the Oracle format, but I wonder is there a more efficient manner.
Cheers for any help Tony
Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 588
Also how do I add 5 days to a date, I have looked at the Date Class, and i cannot see any methods that will allow me to do this.
Cheers Tony
Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 588
Worked out the solution to the second problem.
Calendar c = new GregorianCalendar();
Date d = c.getTime();
System.out.println("CreateCustomerOrder : service() : ToDays Date "+d.toGMTString());
c.add(Calendar.DATE,5);
d = c.getTime();
System.out.println("CreateCustomerOrder : service() : Future Date "+d.toGMTString());

System.out.println("CreateCustomerOrder : service() : Get CustomerOrderID");
Tony
prabhat kumar
Ranch Hand

Joined: Apr 11, 2001
Posts: 114
for converting to sql.Date type
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
I would give the work to Oracle
First of all, in Oracle if you insert into a DATE column, and your date literal is in the default data format (which is usually DD-MON-YY) then you can simply send the string to Oracle like this:

Second, you can use Oracle's to_date function:

Yes the above is a bit crazy with the YYDDMM, but the point is made
Third, to add 5 days why not give it to Oracle?


Normal is in the eye of the beholder
 
Have you checked out Aspose?
 
subject: Mapping Java Date to an Oracle Date.
 
It's not a secret anymore!