浏览帖子,发现一段代码,贴出来共享吧,主要是处理数据库中大块数据,代码如下;
public void queryBlob() throws SQLException, IOException{
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = ConnCreate.getConnection("jdbc:mysql://localhost:3306/test",
"root", "r66t");
String sql = "select info from blob_test where id=3";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
if(rs.next()){
InputStream is=rs.getBinaryStream(1);
File file = new File("d:\\a.bmp");
OutputStream os = new FileOutputStream(file);
int len = 0;
byte[] buffers = new byte[1024];
while((len=is.read(buffers))>0){
os.write(buffers, 0, len);
}
os.flush();
os.close();
is.close();
}
} finally {
ConnCreate.close(conn, stmt, rs);
}