问题描述
我有一个其中包含Blob数据的Sqlite数据库文件.我只知道数据库中有Blob数据,而且知道预期的输出是什么.Blob数据的预期输出应为带有其他文本的Mac地址.
I have a Sqlite database file that has blob data in it.I only know the the database has blob data and I know what the expected output should be.The blob data's expected output should be a Mac address with other text.
我尝试获取十六进制输出,但是并不能真正帮助我获取数据库中已知的预期输出.我还使用了十六进制编辑器和sqlite查看器,但只显示乱码不可读的文本.
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.
这里有一些代码,我试图从blob数据中获取字节,但没有产生我期望的输出. Sqlite在Java中没有getBlob函数.
Here is some code that I tried to get the bytes from the blob data but does not produce the output I expected. Sqlite doesn't have the getBlob function in Java.
if (rs.next()) {
byte[] buffer = rs.getBytes(1);
System.out.println(buffer.toString());
}
blob的预期输出应为:"JOHN A6:44:33:A4:G5:A4"
An expected output from the blob should be :" JOHN A6:44:33:A4:G5:A4 "
这里是示例十六进制转储0008f473eb41e8ba3b1c
Here is a sample Hex dump 0008f473eb41e8ba3b1c
如何在sqlite中以编程方式检索blob数据并解码blob的内容?
How can I programattically retrieve the blob data and decode the contents of the blob in sqlite?
推荐答案
现在,您正在打印byte[]
数组toString()
. Java中的数组无法以有意义的方式实现.
Right now you are printing a byte[]
array toString()
. Arrays in Java don't implement in meaningful way.
您可以尝试使用以下方法将byte[]
数组转换为String
:
You can try converting the byte[]
array into a String
with:
new String(buffer, Charsets.UTF_8)
如果这不起作用,请使用rs.getBinaryStream(1)
获取表示值的InputStream
并按照此答案.
If this doesn't work use rs.getBinaryStream(1)
to get the InputStream
representing the value and read it as per this answer.
这篇关于将来自sqlite数据库的blob数据解码为人类可读的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!