You Are Here:

Community: Developer Discussion Boards

#1 Old problem getting arabic from db and display in midlet - 2007-08-02, 12:49

Join Date: May 2007
Posts: 62
Location: dubai
raghda
Offline
Regular Contributor
hi every body,
i have a midlet that retreives data from sql database and display them.
every thing is ok and with the numbers and with english strings but the problem is that arabic is displayed like that ????

i am sorry if this looks trivial ,i know that i need encoding or some thing to display arabic but i have no idea about encoding

i am using :
midp 2.0
sql 2000
nokia phone N73 for testing

i am sure that my mobile supports arabic

this is the code that i use to get data from the database::
<code>
DataInputStream is =(DataInputStream)c.openDataInputStream();

int ch;
sb = new StringBuffer();

while ((ch = is.read()) != -1) {
sb.append((char)ch);
}

queryResult=sb.toString();
</code>

queryResult looks like this "string,string,string,...."
and i use subString method to separate the strings and display them


any hints are appreciated


raghda
Reply With Quote

#2 Old Re: problem getting arabic from db and display in midlet - 2007-08-02, 20:32

Join Date: Apr 2003
Posts: 6,408
Location: USA, CA
hartti's Avatar
hartti
Offline
Nokia Expert
Does your phone firmware support arabic fonts? If not, you cannot display arabic characters in your MIDlet as there is not system support for it (and you cannot add such language pack on the phone afterwards)

Hartti
Reply With Quote

#3 Old Re: problem getting arabic from db and display in midlet - 2007-08-03, 08:36

Join Date: Nov 2003
Posts: 3,641
Location: Bangalore , India
Send a message via Yahoo to balagopalks
balagopalks's Avatar
balagopalks
Offline
Forum Nokia Expert
Just to add what Hartti suggested, here are some previous similar discussions that would be of some interest to you.
http://discussion.forum.nokia.com/fo...ghlight=arabic
http://discussion.forum.nokia.com/fo...ighlight=UTF-8

Are you using "UTF-8" charectors for encoding Arabic charectors?

Regards
Gopal

__________________
MobiQuil.com
An initiative by Developers for Developers.
http://www.mobiquil.com - Alpha - Launched.
Reply With Quote

#4 Old Re: problem getting arabic from db and display in midlet - 2007-08-05, 14:47

Join Date: May 2007
Posts: 62
Location: dubai
raghda
Offline
Regular Contributor
hi balagopalks,
i really appreciate your reply
i saw the discussions you sent me and i tried to change the encoding in eclipse t UTF-8 and i wrote String s="كتاب"; in my code and i was able to display arabic in my midlet with no more work.

i understood from the discussions that its not that easy to display arabic when dealing with files or databases and this is actually my case,
i am getting data from sql database and i want to display them .

if you have any idea how to do that plz have a look at my code i sent at the beginnig of our discussion

Thanks


raghda
Reply With Quote

#5 Old Re: problem getting arabic from db and display in midlet - 2007-08-07, 06:29

Join Date: May 2007
Posts: 62
Location: dubai
raghda
Offline
Regular Contributor
hi every body ,
my problem has not been solved yet.
please if any body can help plz do as soon as possible

thanks


raghda
Reply With Quote

#6 Old 2007-08-07, 14:21

Join Date: Mar 2003
Posts: 2,617
traud
Offline
Super Contributor
It is not much more difficult, however, you have to take care a bit more and answer these two questions:
– Is Java aware of the encoding of the input source?
– No? Which encoding is used by the input source? Supply that to Java.
Quote:
Originally Posted by raghda View Post
Code:
while ((ch = is.read()) != -1)
{
    sb.append((char)ch);
}
Read of InputStream returns an byte in the range of 0x00-0xFF and not a char which is in the range of 0x0000-0xFFFF. See the Javadoc description of these classes. Again, I recommend to find a tutorial about Byte, Character and String classes.

A correct way in this case would be to wrap your InputStream into an InputStreamReader object and supply the encoding of the data stream in the constructor. Then a char is returned which can be typecasted as you do.
Code:
InputStream stream = c.openDataInputStream();
Reader is = new InputStreamReader(stream, encoding);
Furthermore, you have to figure out that encoding. It could be UTF-8, UTF-16 or many other ones. It could even be that your database returns incorrect data (chars/bytes) already!

However, why do you deal with a DataInputStream? DataInputStream could mean Java knowns the encoding already (see the two questions above) and all you have to do is decode the input stream as it was encoded (readChar or readUTF for example). This depends on your database code, which I do not know. You you use DataOutput there, you can even use writeUTF several times and then readUTF. This would avoid a costly splitting of the complete string.
Last edited by traud : 2007-08-07 at 14:36.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia