2

I have a SQLite(s3db) database with arabic and english words and I placed the local in there as en_US and I am trying to get some arabic data from it but I can't I am getting symbols instead of letters what should I do, I searched for it found that I should work on encoding UTF-8 or.. but I didn't find any details and usefull info please need help,

My code is:

 public String getResult(int id)
    {
        String name = null;
        try
        {
            Cursor c = null;
            c = bdd.rawQuery("select Title from List where _id="+id, null);
            c.moveToFirst();            
            name = c.getString(c.getColumnIndex("Title"));            
            c.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

        return name; 
    }

I used a pre made SQLite database so I wrote the data into it from outside android see link

thanks.

Edit:

I inserted that:
            byte[] b;            
            b = c.getBlob(c.getColumnIndex("Title"));            
            name=b.toString();
            name=new String(b,"UTF-8");
instead of:
            name = c.getString(c.getColumnIndex("Title")); 

So now I am getting question marks in black boxes, I checked to see if my database is UTF-8 encoded and yes it is so what's causing that I am really working on this since hours now any help?!!

EDIT2 SO my database is not utf-8 encoded the arabic words are written as ansi or iso.. and I tried to use:

name = new String(c.getBlob(c.getColumnIndex("Title")), "UTF-8");

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

to transform their encoding to a readable encoding with android but that didn't work as I don't know which encoding to add anyone has an idea about that?

EDit3: So basically I could solve this as I placed the arabic words in notepad++ as UTF-8 and pressed ansi so notepad transformed my words to utf-8 and then I can place them like that in my database and I retrieved data from it and it worked...

4

1 回答 1

0

不要直接写入 Android 中的数据库。您应该使用 ContentProvider。有一个很棒的库,您可以轻松地将数据库与 ContentProviders 一起使用。这是:https ://github.com/TimotheeJeannin/ProviGen

如果你使用它,你可以存储你想要的任何字符串,而不会出现编码问题。

于 2013-06-20T13:14:34.533 回答