Excel encoding / charset to read multibyte characters from java
phani dar
Greenhorn
Joined: Nov 19, 2008
Posts: 4
posted
0
Hi
I have to read multibyte (Japanese and Chinese) characters of an excel sheet and store in database table. I am setting encoding and character set to Excel Driver but its not displaying only ??? question marks. How to read the Japanese and Chinese Characters using Excel jdbcodbc driver. Any help in this regard is appreciated.
Thanks
Sivaraman Lakshmanan
Ranch Hand
Joined: Aug 02, 2003
Posts: 231
posted
0
Hi Phani, Try setting the character encoding to UTF-8.
Regards,
Sivaraman.L
phani dar
Greenhorn
Joined: Nov 19, 2008
Posts: 4
posted
0
Thanks for your reply. I have tried with UTF-8, setting the charSet to driver. Here is the sample code, that I am working on. Could you go through the code, and you can provide any help.
[ November 20, 2008: Message edited by: Martijn Verburg ]
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35232
7
posted
0
Where are you printing this - some kind of console/terminal? Most of those only support displaying ASCII (or maybe ISO-8859), but not something like Chinese/Japanese.
I am writing the strings to text file and opening the text file in Edit Pro that supports UTF-8. But when I open the file, text is displayed as ??? question marks. I need to store the characters as Japanese and Chinese not as ???. How to do this using Excel Driver. Any property or logic is required to do this? [ November 20, 2008: Message edited by: phani dar ]
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35232
7
posted
0
Does the editor recognize the file as Unicode? The code you posted doesn't write a BOM, so the editor may be treating it as some other encoding.
Also, does the editor have access to fonts that can display those characters? Some editors use only monospaced fonts (which would rule out Japanese/Chinese fonts, unless they are especially constructed as monospaced, and recognizable as such by the font engine).
phani dar
Greenhorn
Joined: Nov 19, 2008
Posts: 4
posted
0
Before sending the data to database, I am trying with text file. Once the file opens properly in the editor, I will go with Database. But that is not happening even for text file. The editor has support for unicode.
When I use HSSF POI pakcage the work is done. But POI consumes more memory. The hunch is for JDBCODBC driver to Connect Excel.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35232
7
posted
0
The editor having support for Unicode is not the same as the editor recognizing a file as being in Unicode. It takes a BOM (or smart code in the editor) to determine that.
In the Java code -before you save it to a file- have you checked whether the characters are the correct Unicode characters? That would tell you whether the problem is getting the data through JDBC, or saving the data to a file. (Assuming that the data is not saved correctly; from your description it's not clear to me that it isn't.)
John Dowling
Greenhorn
Joined: Dec 09, 2009
Posts: 2
posted
0
Hi Phani,
Did you locate an odbc driver for excel which supports multibyte characters? I am having same issue, characters read from excel displaying as ???
Thanks,
John Maxall
Greenhorn
Joined: May 03, 2010
Posts: 2
posted
0
I found a solution to the problem of the JDBC-ODBC driver conversion of multibyte characters like Chinese or Japanese. In my case the JDBC driver worked just fine with resultSet.getString(columnName); but not the ODBC driver.
Here is what did work:
Swathi Sriramaneni
Greenhorn
Joined: Nov 23, 2011
Posts: 1
posted
0
Hi John,
Could you please provide in detail solution for reading chinese characters from JDBC?
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32644
4
posted
0
Welcome to the Ranch
John Maxall
Greenhorn
Joined: May 03, 2010
Posts: 2
posted
0
A little more detail on my "solution" (that may not be the solution in all cases, of course)...
In my example, if I remember or guess correctly, the ODBC driver put the bytes in the database. My Java code reads the bytes, then uses the String constructor to convert the bytes to a String.
So instead of
String firstName = resultSet.getString(colIndex);
use
byte[] bytes = resultSet.getBytes(colIndex);
String firstName = new String(bytes, "utf-8");