java 以二进制流的方式读取mysql 中的blob文件,并写入本地文件夹下
2个回答
展开全部
/激橡/枣铅睁配置数据库连接驱动
String sql = xxxxxxxx;//要查询的sql
PreparedStatement ps = conn.prepareStatement(sql);
String path = xxxxxxx;
ResultSet rs = ps.executeQuery();
while (rs.next()) {
InputStream is = rs.getBlob(x).getBinaryStream();//x为要取的BLOB位置
FileOutputStream os = new FileOutputStream(path + "//"
+ "存放的文件名"+“.zip”凳岁);
byte[] buff = new byte[1024];
while ((is.read(buff)) != -1) {
os.write(buff);
}
os.close();
is.close();
}
ps.close();
conn.close();
String sql = xxxxxxxx;//要查询的sql
PreparedStatement ps = conn.prepareStatement(sql);
String path = xxxxxxx;
ResultSet rs = ps.executeQuery();
while (rs.next()) {
InputStream is = rs.getBlob(x).getBinaryStream();//x为要取的BLOB位置
FileOutputStream os = new FileOutputStream(path + "//"
+ "存放的文件名"+“.zip”凳岁);
byte[] buff = new byte[1024];
while ((is.read(buff)) != -1) {
os.write(buff);
}
os.close();
is.close();
}
ps.close();
conn.close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询