Solved

JExcel date format

Posted on 2007-03-22
4
1,202 Views
Last Modified: 2008-01-09
Hi:

I am using JExcel to read data from an excel file published on the web and put it in our internal database. One of the columns in the file is date of format (mm/dd/2003). I do something like:
String theloaddate = null;
theloaddate = cell[0].getContents();
then I write "theloaddate" to a temporary csv file and bulk insert the file to a database table.

I got a SQLException as below:
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 289, column 1 (LoadDate).

I checked the temporary file and found the format of "theloaddate" column somehow got changed to dd/mm/yyyy which is fine, but I just can't see what's the problem with row 289. It looks exactly the same with any other rows.

Please help. Thanks.
0
Comment
Question by:sdc248
  • 2
  • 2
4 Comments
 

Author Comment

by:sdc248
ID: 18771199
ok, I see what's wrong with row 289 now.
That cell is 3/13/2003 (mm/dd/yyyy) but got changed to 13/03/2003 and SQL Server simply doesn't accept month 13. What should I do now?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 18771732
DateFormat dfSource = new SimpleDateFormat("MM/dd/yyyy");
DateFormat dfTarget = new SimpleDateFormat("dd/MM/yyyy");
String theloaddate = dfTarget.format(dfSource.parse(cell[0].getContents()));

// Now you can load it
0
 

Author Comment

by:sdc248
ID: 18772328
In my case it's:
DateFormat dfSource = new SimpleDateFormat("dd/MM/yyyy");
DateFormat dfTarget = new SimpleDateFormat("MM/dd/yyyy");

but I got your point. And it's working. Thanks a lot.

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18772568
:-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countHi challenge 25 84
json format text only 4 65
Non-recursive backtracking, using a stack 1 48
Image decoding from Camera 3 44
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now