【发布时间】:2016-09-09 23:19:27
【问题描述】:
【问题讨论】:
-
你能显示一些代码,你是如何插入数据库的吗?
-
link查看代码
【问题讨论】:
使用ResultSet,您可以检索java.sql.Blob 实例:
Blob blob = resultSet.getBlob("MATERIAL");
然后你可以打开一个输入流:
InputStream input = blob.getBinaryStream();
并将其写入Is it possible to create a File object from InputStream中所述的文件
【讨论】:
从表中获取 Blob:
try (ResultSet rs = statement.executeQuery(query)) {
if(rs.next()) {
fileBlob = rs.getBlob(1);
}
}
将 Blob 的内容保存到新文件中:
try (InputStream ipStream = fileBlob.getBinaryStream(1, fileBlob.length());
OutputStream opStream = new FileOutputStream(new File("path/to/file"))) {
int c;
while ((c = ipStream.read()) > -1) {
opStream.write(c);
}
}
【讨论】: