Link to home
Start Free TrialLog in
Avatar of vaibhavmishra062201
vaibhavmishra062201

asked on

special characters handling

Hi,

I have some German language characters in database e.g. (ü)
When I query the database and display the value, it gets converted to '?'.
How can this be prevented ?

Vaibhav
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Check the database is using UTF-8 encoding...

Check you are using UTF-8 encoding...

Check the bytes coming from the database are the correct bytes for the ü character

Avatar of tomboshell
tomboshell

As I recollect, Java uses 16 bit little Endien.  Most likely the db system and Java are not using the same encoding scheme--it happens alot.  But you can cast the received string value to another encoding type.  I had a similar problem in a project that I am working on.  
Here is an extract from one method that I used to
try {
  String encoding = "UTF-8"; // or try UTF-16
  byte[] bs = sIn.getBytes(encoding);
  sIn = new String(bs, encoding);
} catch (java.io.UnsupportedEncodingException uee) {
  uee.printStackTrace();
  // reset the return variable here
}


The character encodings are discussed at the package level of the Java docs (scoll down.) http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html

http://www.iana.org/assignments/character-sets
>>and display the value, it gets converted to '?'.


Where and how are you displaying it? If in the console, then consoles don't directly support higher characters.
Try to show it in a Swing component
Avatar of vaibhavmishra062201

ASKER

hi tomboshell
i tried ur method but it is still giving '?'
i am retriving it from resultset using getString() or getObject() method.
after this i am displaying it on console or printing it in a file. is there any other place to display it so that i know that it is coming correctly from resultset ?
actually i want to display it in a jsp page in browser, but its not coming correctly even before it goes to jsp.
the database i am using is informix, i dont know what it supports ?
actually, the field was of type Lvarchar, when i converted it to varchar/ char, then it was not converted to '?'.
but varchar has limit of 255 characters and char consumes memory.
any comments ?
I am not familar with the database system you are using but I understand that when you converted it to another format then it translated properly?  But you are now worried about the memory consumption?  I would now wonder what the JDBC driver says about the conversions and with the database which variable type is better to handle character storage.  I would say that if the varchar/char works then use it.  But you know your situation better than I do.  

You may need to check the documentation options to verify that the database is set up to handle the German character codes.  I have read somewhere abut setting the locale and other such options.  


some other info
http://www-3.ibm.com/software/data/informix/pubs/library/220sdk/sqlj/language.fm11.html
Please choose a word to do a SELECT on with a problem character in it and let us know what happens with the following:

String problemWord = resultset.getString(yourField);
new sun.misc.HexDumpEncoder().encode(problemWord.getBytes());
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept tomboshell's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

objects
EE Cleanup Volunteer
Sorry - don't accept that 'decision'
could say it was abondoned since CEHJ's question was not answered.
Yes almost deleted it, but tomboshell provided enough useful information to warrant accepting.
>>Yes almost deleted it

Are you telling us that you have the ability to delete questions?
no just recomend
Ah OK - i was just wondering why you said 'almost deleted it'

Again - i don't agree with the recommendation
So you think it should be deleted?
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial