android的adb下查看sqlite表,中文显示乱码啊,

sqlite>select*fromcity_table;select*fromcity_table;涓婃捣|0澶ц繛|0涓滆帪|0sqlite>... sqlite> select * from city_table;
select * from city_table;
涓婃捣|0
澶ц繛|0
涓滆帪|0
sqlite>
展开
 我来答
匿名用户
2015-11-25
展开全部
插入字符的编码和读出时用的编码要一致,就是说:
假设,数据库中数据是你通过android代码插入,以GB2312编码格式,如:

1

<a href="https://www.baidu.com/s?wd=db&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9rju-ujDsrycznWn1PW630AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtdP1f3Pjm1PHD" target="_blank" class="baidu-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="baidu-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="baidu-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="baidu-highlight">sn</a>;

try {

<a href="https://www.baidu.com/s?wd=sn&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9rju-ujDsrycznWn1PW630AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtdP1f3Pjm1PHD" target="_blank" class="baidu-highlight">sn</a> = new String(val,"gb2312");

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

}

就是说,插入和读取要么都做转换,要么都不做(android默认UTF-8格式)。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式