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> 展开
select * from city_table;
涓婃捣|0
澶ц繛|0
涓滆帪|0
sqlite> 展开
1个回答
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格式)。
假设,数据库中数据是你通过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格式)。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |