views:

55

answers:

3

Hi Folks,

I have stored Spanish text into the SQlite database and I am retrieving the same through the java code using row.getString() method of BlackBerry API, But I am unable to fetch the exact text from the database, only the accent characters are displaying differently in to the device(BlackBerry bold 9700). Where I am doing wrong please point me to the right direction.

Best Regards,

Vinayak

A: 

This looks like a problem with the encoding. You have to use the same encoding when loading the text as you used when storing it. This blog is a good reference for unicode problems.

Space_C0wb0y
+2  A: 

It is surely a problem with the Charset encoding. It's a common problem using spanish accents and tildes. The SQLite uses UTF-8, so you have to check if your application uses UTF-8 or else.

EDIT: set the default encoding at BlackBerry API You have to set the system property microedition.encoding. Reference: http://www.blackberry.com/developers/docs/4.5.0api/java/lang/System.html

You can set this property at the command line: java -Dmicroedition.encoding="UTF-8" MyApp

Tomas Narros
According to [this](http://www.sqlite.org/version3.html) it also supports UTF-16.
Space_C0wb0y
Yea sure I am using UTF-8 encoding for the SQlite, But how do I ensure that my application is using the same encoding (i.e UTF-8).
Vinayak.B
True. From version 3.0. Thanks for the point.
Tomas Narros
As it seems, BlackBerry API uses as default the ISO-8859-1 encoding: http://www.blackberry.com/developers/docs/5.0.0api/java/lang/String.html
Tomas Narros
Many Thanks Tomás, Is there any way to set my application to use UTF-8 encoding?
Vinayak.B
@Vinavayak: I have edited my answer with the System property of the JVM to set the default encoding
Tomas Narros
@Tomas Could you please let me know how to set the system property, does I have to set it programatically or any configuaration setting.
Vinayak.B
On the command to start the java application you have to add a -D option setting the property. By the example: java -Dmicroedition.encoding="UTF-8" com.test.MyApp . I have added this snippet to my anser too.
Tomas Narros
Thanks Tomas, I never come across this process while deploying the app into the device, I will create the COD file by using Run in Eclipse then that COD I load into the device using BlackBerry Java Loader "Javaloader -u myfile.cod"
Vinayak.B
A: 

row.getString() does not allow any specification of the encoding - so the OS code should be doing the right thing when retrieving a string from the database. My experience with SQLite on BlackBerry is that OS builds around 5.0.0.4xx have a bug where the database encoding is not respected on retrieval. I've had to work around this by doing

new String(row.getString().getBytes(), "UTF-8")

But of course, only on the problematic OS versions, as this would break any correct implementation of row.getString().

The versions with this issue that I've encountered so far are: 5.0.0.442 and 5.0.0.423

Michael Donohue