android的adb下查看sqlite表,中文显示乱码啊,
发布网友
发布时间:2022-04-22 20:45
我来回答
共1个回答
热心网友
时间:2022-04-08 12:26
插入字符的编码和读出时用的编码要一致,就是说:
假设,数据库中数据是你通过android代码插入,以GB2312编码格式,如:
1
<a href="https://www.baidu.com/s?wd=db&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9rju-ujDsrycznWn1PW630AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtdP1f3Pjm1PHD" target="_blank" class="-highlight">db</a>.execSQL("insert into question_tb values(?,?,?,?,?,?,?)",new String(val,"gb2312"));
插入到表:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"Create table IF NOT EXISTS question_tb(" +
"code int," +
"is_finished int," +
"is_english int,"+
"pic_name varchar(64)," +
"ans_back <a href="https://www.baidu.com/s?wd=BLOB&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9rju-ujDsrycznWn1PW630AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtdP1f3Pjm1PHD" target="_blank" class="-highlight">BLOB</a>," +
"ans_true varchar(64)," +
"info int"+
")";
读出就是:
1
2
3
4
5
6
7
8
9
10
11
12
13
byte[] val = cursor.get<a href="https://www.baidu.com/s?wd=Blob&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9rju-ujDsrycznWn1PW630AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtdP1f3Pjm1PHD" target="_blank" class="-highlight">Blob</a>(cursor.getColumnIndex("ans_back"));
String <a href="https://www.baidu.com/s?wd=sn&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9rju-ujDsrycznWn1PW630AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtdP1f3Pjm1PHD" target="_blank" class="-highlight">sn</a>;
try {
<a href="https://www.baidu.com/s?wd=sn&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9rju-ujDsrycznWn1PW630AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtdP1f3Pjm1PHD" target="_blank" class="-highlight">sn</a> = new String(val,"gb2312");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
就是说,插入和读取要么都做转换,要么都不做(android默认UTF-8格式)。