【发布时间】:2020-01-11 21:07:31
【问题描述】:
如何识别结果集条目是 BLOB 还是压缩 BLOB? 如果 BLOB 被压缩,我需要解压缩它。
PreparedStatement stmt = conn.prepareStatemant("select BLOB from X");
ResultSet rs = stmt.executeQuery();
while(rs.next()){
Blob blob = rs.getBlob(1);
if(isZippedBlob(blob)){
Blob unzipBlob = unzipBlob(blob);
}
}
}
我会很感激
的实现版本boolean isZippedBlob(Blob)
或任何我能识别压缩 BLOB 和 BLOB 的算法。
【问题讨论】:
-
Zip 文件有一个 zip 文件头。您(或库)可以检查第一个字节以查看它是否具有 zip 标头。
-
@Kayaman 感谢您的建议。我使用 rs.getBlob(1).getBytes(1, (int) rs.getBlob(1).lengt());但我得到的值不适合这个特定的标题。