mardi 5 juillet 2016

Android + Java + SQLite encoding error

When i save this string to a database:

@ there is a hole.

when reading it back i get:

@ there is a hol

Notice the missing last to characters: e.

if i try to save:

@ theres a hole.

I correctly read back the string. Since the error depends on the lenght of the string, i think it might have something to do with unicode... but i am not sure.

Anybody knows what is going on? Here is the code i use to save the string to database:

lQuery = "UPDATE notices SET note='@ there is a hole.' where id=3";
SQLiteDatabase mdb = (SQLiteDatabase) DBconn;
try {
    mdb.execSQL(lQuery);
} catch (Exception ee) {
    DBlasterr = ee.getMessage();
};

And here is how i am retrieving the string:

lQuery = "SELECT * FROM notices where id=3";
try {
   SQLiteDatabase mydb = (SQLiteDatabase) DBconn;
   rs = mydb.rawQuery(lQuery, null);
   rs.moveToFirst();       
   Log.d("======", "returned: " + rs.getString(rs.getColumnIndex("note")));
} catch (Exception ee) {
    DBlasterr = ee.getMessage();
}

Aucun commentaire:

Enregistrer un commentaire