[英]Decoding blob data from a sqlite database into a human readable text
I have a Sqlite database file that has blob data in it. 我有一个其中包含Blob数据的Sqlite数据库文件。 I only know the the database has blob data and I know what the expected output should be.
我只知道数据库中有Blob数据,而且知道预期的输出是什么。 The blob data's expected output should be a Mac address with other text.
Blob数据的预期输出应为带有其他文本的Mac地址。
I tried getting the hex output but does not really help me with getting the expected output that I know is in the database. 我尝试获取十六进制输出,但是并不能真正帮助我获取数据库中的预期输出。 I also used a Hex editor and sqlite viewer but only shows gibberish unreadable text.
我还使用了十六进制编辑器和sqlite查看器,但仅显示乱码不可读的文本。
Here is some code that I tried to get the bytes from the blob data but does not produce the output I expected. 这是一些我尝试从Blob数据中获取字节的代码,但未产生预期的输出。 Sqlite doesn't have the getBlob function in Java.
Sqlite在Java中没有getBlob函数。
if (rs.next()) {
byte[] buffer = rs.getBytes(1);
System.out.println(buffer.toString());
}
An expected output from the blob should be :" JOHN A6:44:33:A4:G5:A4 " 斑点的预期输出应为:“ JOHN A6:44:33:A4:G5:A4”
Here is a sample Hex dump 0008f473eb41 e8ba3b1c 这是一个示例十六进制转储0008f473eb41 e8ba3b1c
How can I programattically retrieve the blob data and decode the contents of the blob in sqlite? 如何在sqlite中以编程方式检索blob数据并解码blob的内容?
Right now you are printing a byte[]
array toString()
. 现在,您正在打印一个
byte[]
数组toString()
。 Arrays in Java don't implement in meaningful way. Java中的数组无法以有意义的方式实现。
You can try converting the byte[]
array into a String
with: 您可以尝试使用以下方法将
byte[]
数组转换为String
:
new String(buffer, Charsets.UTF_8)
If this doesn't work use rs.getBinaryStream(1)
to get the InputStream
representing the value and read it as per this answer . 如果这不起作用,请使用
rs.getBinaryStream(1)
来获取表示该值的InputStream
并按照此答案读取它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.