Solved

JExcel date format

Posted on 2007-03-22
4
1,205 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

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 …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

822 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