Android 将重音字符保存和检索到mysql数据库
我在将带有重音的字符串保存到数据库并检索它时遇到一些问题 这是我的函数,用于将新位置保存到数据库中。它获取“myId”和“location”并插入它们。那里的println显示了我期望的项目,带有重音。我用的例子是马扎拉Android 将重音字符保存和检索到mysql数据库,android,database,utf-8,android-sqlite,Android,Database,Utf 8,Android Sqlite,我在将带有重音的字符串保存到数据库并检索它时遇到一些问题 这是我的函数,用于将新位置保存到数据库中。它获取“myId”和“location”并插入它们。那里的println显示了我期望的项目,带有重音。我用的例子是马扎拉 public long createLocationRecord(String location, int myId) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values
public long createLocationRecord(String location, int myId) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_OWMID, myId);
values.put(KEY_NAME, location);
System.out.println("newItem in DB = "+location);
long callSQL = db.insertWithOnConflict(TABLE_LOCATION, null, values, SQLiteDatabase.CONFLICT_IGNORE);
if(callSQL==-1)
db.update(TABLE_LOCATION, values, KEY_OWMID + '=' + owmId, null);
return callSQL;
}
这是我检索所有位置项的函数。这里的println打印的是Mezzarra,没有重音符号。我错过什么了吗?我需要更改我的数据库吗?这只是一个普通的Android SQLite数据库,我正在通过它打开
public ArrayList getLocationList(){
ArrayList=新建ArrayList();
SQLiteDatabase db=this.getWritableDatabase();
String selectQuery=“选择*”
+“从”+表格位置
+“订购人_idasc”;
游标c=db.rawQuery(selectQuery,null);
如果(c!=null)
c、 moveToFirst();
if(c.moveToFirst()){
做{
System.out.println(“newItem get FROM DB=“+c.getString(c.getColumnIndex(KEY_NAME)));
添加(c.getString(c.getColumnIndex(KEY_NAME));
}而(c.moveToNext());
}
c、 close();
退货清单;
}
感谢任何人提供的帮助。您查看过这篇文章吗?&这里的评论展示了一个很好的例子,我认为您可以通过取消重音符号来删除强音中的重音符号。我的目标是留住他们。到目前为止,我所看到的一切都表明,标准的SQLite DB应该能够像我尝试的那样保存和检索它们。
public ArrayList<String> getLocationList() {
ArrayList<String> list = new ArrayList<String>();
SQLiteDatabase db = this.getWritableDatabase();
String selectQuery = "SELECT * "
+ "FROM " + TABLE_LOCATION
+ " ORDER BY _id ASC";
Cursor c = db.rawQuery(selectQuery, null);
if (c != null)
c.moveToFirst();
if (c.moveToFirst()) {
do {
System.out.println("newItem GETTING FROM DB = "+c.getString(c.getColumnIndex(KEY_NAME)));
list.add(c.getString(c.getColumnIndex(KEY_NAME)));
} while (c.moveToNext());
}
c.close();
return list;
}