?
Solved

JExcel date format

Posted on 2007-03-22
4
Medium Priority
?
1,235 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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 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