瀏覽帖子,發現一段代碼,貼出來共享吧,主要是處理數據庫中大塊數據,代碼如下;
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);
}