【发布时间】:2019-11-16 01:19:48
【问题描述】:
我正在学习制作字典应用程序。我有一个小数据库,一张表中有 20 个单词,另一张表中有 20 个单词的定义。但是定义是 BLOB 类型的。而且我无法获得其正常的字符串类型。这是我尝试过的代码:
public byte[] word_value(int a) throws UnsupportedEncodingException {
c = database.rawQuery("select body from items A inner join items_info B on A.id = B.id where B.id = '" + a + "';" , null);
while (c.moveToNext()){
byte[] blob = c.getBlob(0);
String s = new String(blob, StandardCharsets.UTF_8);
Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
}
return null;
}
获取值但不转换为字符串
感谢任何帮助
【问题讨论】:
-
Blob blob = rs.getBlob("image"); byte [] bytes = blob.getBytes(1l, (int)blob.length());String s = new String(bytes);
标签: android arrays sqlite blob