aspose file tools*
The moose likes JDBC and the fly likes Display problem with Japanese characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Display problem with Japanese characters" Watch "Display problem with Japanese characters" New topic
Author

Display problem with Japanese characters

Bhavani Kumar
Greenhorn

Joined: Feb 22, 2005
Posts: 15
I am fetching a Japanese string from Oracle Database and displaying it on the browser. But the characters are shown on the browser like ???. Inserted the Japanese string into DB using the unistr() function.INSERT INTO MESSAGES (MESSAGE_ID,MESSAGE) VALUES (1,unistr('\0041\0063\0063\0065\0073\0073\0020\004d\0061\006e\0061\0067\0065\006d\0065\006e'));

I got this in my jvm logs 'ISO8859-1' when I printed System.getProperty("file.encoding").

select * from v$nls_parameters where parameter in ('NLS_CHARACTERSET') yields 'UTF8' in my DB.

Any pointers on how the Japanese characters could be displayed correctly ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

But the characters are shown on the browser like ???

I think that you have to check the following first, to understand whether the problem comes from inserting, fetching or displaying:
1. Using an SQL editor, check the content of the database. Make sure the string is properly inserted. (I wonder why you are using unicode strings like this...)
2. What does the String contains after fetching data from the DB ? Either debug it, or output the String in a file and open the file with an editor which supports unicode.
3. How did you set the web page encoding ?

[My Blog]
All roads lead to JavaRanch
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18672
    
    8

Have a look at this article: Character Conversions from Browser to Database.
Bhavani Kumar
Greenhorn

Joined: Feb 22, 2005
Posts: 15
1. Using an SQL editor, check the content of the database. Make sure the string is properly inserted. (I wonder why you are using unicode strings like this...)
2. What does the String contains after fetching data from the DB ? Either debug it, or output the String in a file and open the file with an editor which supports unicode.
3. How did you set the web page encoding ?


1. Japanese string is properly inserted in the DB. I had read in Oracle Technical Network that non-ascii strings could be inserted in this way. When I query this string using "select unistr('\0041\0063\0063\0065\0073\0073\0020\004d\0061\006e\0061\0067\0065\006d\0065\006e1\006e\0061\0067\0065\006d\0065\006e\0074\0020\0054\006f\006f\006c\0020\304b\3089\306e') from dual;" then it is showing me the correct japanese message.
2. String contains all ???. I saw printing it on the browser as well as in the log.
3. Web page encoding is set in the Websphere server that we use and is set to 'ISO8859-1'.

I have tried converting the mydatabasestring to correct japanese string in below ways but still only question marks (???) appear.

out.println("1."+new String(mydatabasestring.getBytes("UTF-8"),"ISO-2022-JP"));
out.println("2."+new String(mydatabasestring.getBytes("ISO-2022-JP"),"UTF-8"));
out.println("3."+new String(mydatabasestring.getBytes("ISO-2022-JP"),"ISO-2022-JP"));
out.println("4."+new String(mydatabasestring.getBytes("Cp1252"),"Cp1252"));
out.println("5."+new String(mydatabasestring.getBytes("ISO-2022-JP"),"Cp1252"));
out.println("6."+new String(mydatabasestring.getBytes("Cp1252"),"ISO-2022-JP"));
out.println("7."+new String(mydatabasestring.getBytes("UTF-8"),"Cp1252"));
out.println("8."+new String(mydatabasestring.getBytes("Cp1252"),"UTF-8"));

Is there anything that I am missing here ???
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Not a "beginning" question. Moving thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display problem with Japanese characters