


public class BlobTest {
@Test
public void test1() throws Exception {
String sql="insert into img(img) values (?)";
Connection conn=JdbcUtil.getConn();
PreparedStatement pst=conn.prepareStatement(sql);
pst.setBlob(1, new FileInputStream("C:/Users/Desktop/img/b1.jpg"));
pst.executeUpdate();
JdbcUtil.close(null, pst, conn);
}
public void test2() throws SQLException, Exception {
String sql="select * from img where id=?";
Connection conn=JdbcUtil.getConn();
PreparedStatement pst=conn.prepareStatement(sql);
pst.setInt(1, 3);
ResultSet rs=pst.executeQuery();
if(rs.next()) {
Blob blob=rs.getBlob("img");
InputStream in=blob.getBinaryStream();
Files.copy(in, Paths.get("C:/newwow"));
}
JdbcUtil.close(rs, pst, conn);
}
}