当前位置:   article > 正文

BLOB类型和TEXT类型_不能将类型“blob”分配给类型“binarydata

不能将类型“blob”分配给类型“binarydata


  1. public class BlobTest {
  2. @Test
  3. public void test1() throws Exception {
  4. String sql="insert into img(img) values (?)";
  5. Connection conn=JdbcUtil.getConn();
  6. PreparedStatement pst=conn.prepareStatement(sql);
  7. pst.setBlob(1, new FileInputStream("C:/Users/Desktop/img/b1.jpg"));
  8. pst.executeUpdate();
  9. JdbcUtil.close(null, pst, conn);
  10. }
  11. public void test2() throws SQLException, Exception {
  12. String sql="select * from img where id=?";
  13. Connection conn=JdbcUtil.getConn();
  14. PreparedStatement pst=conn.prepareStatement(sql);
  15. pst.setInt(1, 3);
  16. ResultSet rs=pst.executeQuery();
  17. if(rs.next()) {
  18. Blob blob=rs.getBlob("img");
  19. InputStream in=blob.getBinaryStream();
  20. Files.copy(in, Paths.get("C:/newwow"));
  21. }
  22. JdbcUtil.close(rs, pst, conn);
  23. }
  24. }

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号