Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

New Contributor
Posts: 3
Registered: ‎03-15-2011
My Device: 9000, 9700
My Carrier: Vodafone

Re: UTF8 encoding and SQLite database problems

Hi all, 


since I am new to Blackberry development, I ran into some problems concerning my database as well. I am developing an app in 4 different languages. I tried to solve my encoding problem (which is excactly the same as Patchou noted before) by his approach with inserting a single character into the databse and checking how it will be returned by the database or Row.getString().


This worked quite well on my Bold 9000, but on the Bold 9700 it didn't. I insert a "ß" and it is returned these two "garbage" characters in BOTH devices. But on the 9700 it just shows question marks instead of special characters, "umlaut", arabic oder japanese characters.


I am not really an expert at encoding/decoding...hopefully someone can help me here or give me new input, since I am really desperate to know what the problem is here and how i can fix it.




PS: 9000 (, 9700 (

Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: UTF8 encoding and SQLite database problems

I have reviewed Patchou's workaround, and to be honest, thought it was potentially 'flaky'.  The issue is, for databases that do not supply UTF-8 Strings, the text has been converted to characters using ISO-8859-1.  Taking this text and doing this:


byte[] aChars = sText.getBytes("ISO-8859-1");

does not, for me, guarantee that you will get the same byte array as was originally supplied.


The approach that I am using

(see http://supportforums.blackberry.com/t5/Java-Development/UTF8-encoding-and-SQLite-database-problems/m...

does guarantee that you will get the correct data.  The issue is this approach is it is a significant overhead on devices where it is not needed.


So you could reduce this by determining if there is an issue with UTF-8 text data on the device, and if there is, obtain the text variables in hex and then convert to text.  Otherwise use normal Select processing.

New Contributor
Posts: 3
Registered: ‎03-15-2011
My Device: 9000, 9700
My Carrier: Vodafone

Re: UTF8 encoding and SQLite database problems



it seems like the database on 9700 is utf encoded while the one on the 9000 is not. I found a mistake in checking which encoding is used. What I do now is insert an arabic character in unicode encoding.



String character = "\u0645";


If the database returns a question mark ("?") with the select statement the encoding is not utf so I ensure UTF with every request statement I do afterwards. Both solutions, including the hex() method in the statement itself and converting the hex data to a utf-8 string as well as



byte[] chars = text.getBytes("ISO-8859-1");
String utf8 = new String(chars, "UTF-8");

work for me. 


Thanks so much, you both helped me a lot. Smiley Happy