• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 806
  • Last Modified:

Java Parse Date into Oracle

Hello

I have a parser JSP which reads a page.

I receive date in different formats:

MM/DD/YYYY

or mm/dd/yyyy hh:mm:ss

or alot of other formats.

Even this:
Fri, 28 Sep 2007 21:56:59 +0000

I want to put this to my Oracle db which if timedate. How can I convert all kind of formats to time/date, like this:

29-SEP-07

A simple Java code is enough.

Thanks from now!
0
CSecurity
Asked:
CSecurity
2 Solutions
 
basicinstinctCommented:
0
 
CEHJCommented:
Accepting data in many formats is asking for trouble. You should do the reverse, constraining input as tightly as possible. Use drop downs, cleary marking which fields are which
0
 
objectsCommented:
all you can really do is loop thru your formats trying each one until you find one that works (ignoring exceptions thrown for ones that do not).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CSecurityAuthor Commented:
Any example code related to this stuff?
0
 
CEHJCommented:
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
String formDate = req.getPararmeter("month") + "/" + req.getPararmeter("date") + "/" + req.getPararmeter("year");
Date d = df.parse(formDate);
0
 
CEHJCommented:
Of course all that req.getPararmeter should be req.getParameter
0
 
objectsCommented:
When inserting date into oracle use a pREPAREDStatement, that will avoid any need to format your parsed timestamp.
0
 
CEHJCommented:
:-)
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now