problem may be in how you insert it, check that code
Main Topics
Browse All Topics
Hi all,
I've seen this question asked, but haven't seen an answer that I think applies to my situation. So, here goes:
First, I am a novice Java programmer, as I am sure you will see. My problem is this:
1. I am attempting to migrate data from one database to another.
2. Migration is being done using a Java program
3. The source database contains a field (which we will call: Source_Date), that contains a text value. For purposes of this question, the value contained in the field is: "03-SEP-2006 14:22". Source_Date is represented as a String object in our TopLink model.
4. The field to which I wish to copy this text value is a date/time field, and is represented as a Date object in our TopLink model.
So, the question I have is how do I transform the String object into a Date object? I have tried something like this:
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-y
This seems to work, but, the value in the example above always winds up being something like this:
03-SEP-1016 14:0
Anyone have any ideas? If I have bunged something up, let me know and I will provide more detail. Assinging this question a value of 500 points based solely on urgency. Thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Think this will work:
private static Date getDate(String dateString){
Date date = null;
try{
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yy
date = df.parse(dateString);
}catch(Exception e){
e.printStackTrace();
}
return date;
}
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-y
but, the value in the example above always winds up being something like this:
03-SEP-1016 14:0
This is because you have formatted it in that way!
Give the code a try!
Regards
A) Java date sucks, use Joda Time
http://joda-time.sourcefor
B)This seems to work, but, the value in the example above always winds up being something like this:
After this:
date = df.parse(dateString);
date = 03-SEP-1016 14:0 ???
Or does your new DATABASE value = 03-SEP-1016 14:0 ???
CEHJ,
As you requested:
Source_Field contains the following text value: "03-SEP-2006 14:00"
Code to convert from String to Date looks like this:
Public static Date convertStringToDate(String
Date newDate = null;
SimpleDateFormat dFormat = new SimpleDateFormat("dd-MMM-y
newDate = dFormat.parse(inputStrDate
return newDate;
}
*****
As all can see, the above code is rather simple, and I would have expected it to work. What complicates matters is that I am testing to see if the date looks OK using a Web-based app, and the date does not look right there. The app is a fairly hefty J2EE Java-based website that serves up customer data to internal CS personnel. I did not code the app, and there is a certain level of disconnection between me and the developers. Further complicating matters is the fact that Toplink generated the Oracle schema, so it is difficult to discern where exactly all of the migrated data is being placed (I engage the DB at the Toplink object model level, which bears little resemblance to the actual db schema).
>It may be a view issue. Could be that whatever you're viewing the date through does not use the same format (00==0)
Well, that might indeed be true. I should ammend my original post and say that the date, aftering being migrated, looks like this:
03-AUG-1016 14:0
Now, your comment would address why the time looks funky, but not why the month and year appear to be off by:
Month: 1
Year: 1900
This happens consistently, no matter what date value I attempt to convert. The month is always less by 1 (OCT becomes SEP, etc.) and the year is always less by 1900 years.
Perhaps I will not find the answer directly, but your comments may at least point me in the right direction. I, being a novice, find myself drowning in a sea of Java.
OK. You have to understand that a Date gets involved in the model/view paradigm. In essence a Date is just a number (the model). The view (normally its string representation) doesn't alter the model. What you're looking at is a *view* problem. We can tell that for certain, since, as i said above
>>(00==0)
so the model is identical.
You need to find out why the view is as it is
Well, this I did compare the converted value to the original value (a comparison of long value to long value) and it looked right. So, the problem would either have to be at the DB or presentation layer. I believe it is at the pres layer - the underlying db field is a Date datatype, so do not think I would have an issue there.
Business Accounts
Answer for Membership
by: CEHJPosted on 2006-09-05 at 14:07:20ID: 17459076
>>
but, the value in the example above always winds up being something like this:
03-SEP-1016 14:0
>>
Shouldn't do. Can you post the full code?