• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Unicode Support in J2se Application

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oracle supports Unicode, and Java supports Unicode. What sort of client are you displaying this text in?
 
Dharmendra Kumar Singh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you needs any detail then let me know.
Waiting for your reply..
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My all the components are using UTF-8 encoding.
Tell me if you want to know more.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please give some sample code which i should
do for my application its will help me.
 
Dharmendra Kumar Singh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will try and get back to you soon
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
any update on this?
can we assume its working now?
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Popeye has his spinach. I have this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic