wood burning stoves 2.0*
The moose likes Java in General and the fly likes Unicode Support in J2se Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Unicode Support in J2se Application" Watch "Unicode Support in J2se Application" New topic
Author

Unicode Support in J2se Application

Dharmendra Kumar Singh
Greenhorn

Joined: Mar 02, 2008
Posts: 10
My application reads data from database(oracle 10g)and it displays
whatever it gets from database but there are some text which are written in hebrew and russian it is not displaying that text.
Can anybody help
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Oracle supports Unicode, and Java supports Unicode. What sort of client are you displaying this text in?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Dharmendra Kumar Singh
Greenhorn

Joined: Mar 02, 2008
Posts: 10
Thanks for quick reply..
See my application has three components UI which is written in C#,My business logics are written in java component and last is database which is oracle 10 g.Java component fetches data from database and sends to UI (C#)in xml format and Ui Displays that data.
Whatever data i are getting in java component is corrupted
as an example i am getting this
hebrew text = ���������? and
russian text = ���������
UI is displaying whatever it is getting from java component.
I tried many things but thigs are not working as per expectation.
Dharmendra Kumar Singh
Greenhorn

Joined: Mar 02, 2008
Posts: 10
If you needs any detail then let me know.
Waiting for your reply..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
Do all components along the way use the same character encoding? Java uses Unicode internally, so if either C# or Oracle use something else, then the code needs to perform explicit conversions.

Paul's question is pertinent, though: How are you determining that the data is corrupt? If you're looking at a console (or a file in a non-Unicode-capable editor), then those may not be able to display the actual characters.

Also tell us what the things were that you tried, and how they didn't do what you thought they would.
[ March 03, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Daniel Chemko
Ranch Hand

Joined: Feb 27, 2008
Posts: 32
Here's one possible issue to your issue:
http://tripoverit.blogspot.com/2007/04/javas-utf-8-and-unicode-writing-is.html

PS: You may need to explicitly define the C# Unicode input stream when reading java's output if C# isn't smart enough to know the difference between UTF-8/UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE, etc...

PPS:
BE == Big Endian == hex 10 equals 16
LE == Little Endian == hex 10 equals 1
Dharmendra Kumar Singh
Greenhorn

Joined: Mar 02, 2008
Posts: 10
Hi All,
First of all let me clear your doubt when i am installing java component on linux machine its working fine but its not working Window xp(SP-2).Hebrew and russian languages and fonts are installed on my XP system.
Even i tried "Daniel Chemko" code but its not working.

have a look on this java code this will help you understanding the problem

OutputStream os = getResponseStream();
String outbytesStr = null;
if(os != null)
{
try
{
try {
byte [] resStr = os.toString().getBytes("UTF-8");
outbytesStr = new String(resStr,"UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
response = outbytesStr;

this response is of string type and i am sending response as xml to C#
application .

One thing more my C# ,Java component and Oracle 10g are interacting through
SOAP calls.

Hope this time am able to expalin my problem.

Looking forward for your reply..
Dharmendra Kumar Singh
Greenhorn

Joined: Mar 02, 2008
Posts: 10
My all the components are using UTF-8 encoding.
Tell me if you want to know more.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
If it's neither a BOM nor an encoding problem, then you need to check at which point it gets corrupted. It is OK in the database? Is what the Java code gets from the DB still OK? Is what the Java code send to C# still OK? Is what C# gets from Java still OK? Breaking it down like this will give you a hint where to start looking for the problem.

And remember: displaying text in a console or a file may not work, so you need to think about how to ascertain whether the characters are OK or not.
Dharmendra Kumar Singh
Greenhorn

Joined: Mar 02, 2008
Posts: 10
See result which i am getting from database is in OutputStream then
i am converting this outputstream to string just by writing code
OutputStream os = getResponseStream();
response = os.tostring()

getResponseStream() returns outputstream and this response has corrupted text so i am able to see data at this place only.

Now any comments?
Dharmendra Kumar Singh
Greenhorn

Joined: Mar 02, 2008
Posts: 10
i would like to add one more things
I made one dummy application which can directally communicate with database
then i am getting the proper data but once i am introducing this java component then i am getting this corrupted data.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
OutputStream os = getResponseStream();
response = os.tostring()

This is incorrect. The toString method of a stream does not return the bytes that make up the stream and return them as a string (which should be apparent if you look at the length of what it returns, and compare that to what you are expecting). You need to write code that reads the bytes or characters, and then writes them to the response stream.
Dharmendra Kumar Singh
Greenhorn

Joined: Mar 02, 2008
Posts: 10
Can you please give some sample code which i should
do for my application its will help me.
Dharmendra Kumar Singh
Greenhorn

Joined: Mar 02, 2008
Posts: 10
you are asking me to include this code in my application

OutputStream os = getResponseStream();
String outbytesStr = null;
if(os != null)
{
try
{
try {
byte [] resStr = os.toString().getBytes("UTF-8");
outbytesStr = new String(resStr,"UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
response = outbytesStr;

but still its not working...

Now what should i do?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
As I mentioned before, "os.toString()" does not return anything meaningful. You need to read the bytes from the streams. If you're unsure of how to do that, I'd suggest to read up on how streams work in Java. In particular, you need to be clear about the differences between byte streams and character streams, and the role encodings play to convert one to the other.
Dharmendra Kumar Singh
Greenhorn

Joined: Mar 02, 2008
Posts: 10
I will try and get back to you soon
Rajendra Murthy
Greenhorn

Joined: Mar 30, 2008
Posts: 8
Hi,
any update on this?
can we assume its working now?
Anshul Malpani
Greenhorn

Joined: Mar 05, 2007
Posts: 13
I have also faced the same problem. So while creating the Outputstream I have passed the Encoding format CP-1251 then it started working try to pass your encoding format. One more thing save your XMl file in Desktop and try to open it with uniread. If its looking corrupted then if your are using VM then save the Vm with your encoding format


SCJP-5.0
 
 
subject: Unicode Support in J2se Application