*
The moose likes Beginning Java and the fly likes Converting String to Date??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Converting String to Date???" Watch "Converting String to Date???" New topic
Author

Converting String to Date???

Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
I am trying to convert some data I get as a string into a date so I can insert it into a database. Here are the code snippets I am using.


If I send a string 9/30/2006 I get "Sat Sep 30 00:00:00 BST 2006"
back when I call getDate. The database is giving me an error of non-numeric character found where numeric value expected...

Any ideas?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8877
    
    8

What database are you using?
What does your SQL statement look like?
What type is the database field you are trying to change?
You give us a result if you call "getDate". What do you call "getDate" on? A result set? A Date instance?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
Database = oracle;
SQL = a simple "Insert into table (field) values ( dDate );
Field = I am taking a java string and inserting it into an oracle date field (is that what you were asking?)
getDate = getDate is in a java data object (just a bunch of getters and setters) it returns a date object. when I print it out I get "Sat Sep 30 00:00:00 BST 2006" where the String was 9/30/2006.

I did develop an answer but would still like further input as I might not have the best answer.
My answer was to ignore the java Date altogether and just call the oracle to_date function in the sql I passed. The to_date function will except a string (9/30/2006) and convert it to a date. perhaps not the best solution as the database is having to do the work but it seems to be an answer.

Thanks for any input.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

What you will want to do is use a PreparedStatement here.



This will allow the JDBC driver to handle the date conversions. If you are using the date as a String, then you will have to call Oracles TO_DATE function.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting String to Date???