我使用以下代码片段来读取存储在SQLite数据库[在Windows上创建]的Blob字段中的图像。
while (rs.next()) {
InputStream is = rs.getBinaryStream(1);
byte[] buffer = new byte[1024];
while (is.read(buffer) > 0) {
fos.write(buffer);
}
但是,当创建用于Android设备的SQLite数据库和存储在此类数据库中的Blob字段中的图像时,这不起作用。在我的测试中,使用上面的代码片段创建的文件都是无法识别的格式。
使用以下代码段会导致错误。
while (rs.next()) {
Blob imageBlob = rs.getBlob(2);
InputStream is = imageBlob.getBinaryStream(0,imageBlob.length());
//Writing to output file.
byte[] buffer = new byte[1024];
while (is.read(buffer) > 0) {
fos.write(buffer);
}
报告的错误是:
java.sql.SQLException:未由SQLite JDBC驱动程序实现
在搜索了此论坛中的帖子后,我了解sqlite-jdbc-3.8.11.2.jar不支持 Blob 。
我似乎无法使用Android的Bitmap类读取存储在Blob字段中的图像。 [B@dde6e5
是存储在Android SQLite表的Blob字段中的图像值的示例。