显示来自PostgreSQL数据库的图像bytea

显示来自PostgreSQL数据库的图像bytea,第1张

显示来自PostgreSQL数据库图像bytea

像是

// Run a query again the IMAGE table to fetch the image with the given idpublic Image readImage(Connection conn, int id) throws SQLException {  PreparedStatement pstmt = null;  try {    pstmt = conn.prepareStatement("SELECt contents FROM image WHERe id = ?");    pstmt.setInt(1, id);     ResultSet rs = ps.executeQuery();    if (rs.next()) {      InputStream is = rs.getBinaryStream(1);      return ImageIO.read(is);    } else {      return null;    }  } finally {    if (pstmt != null) {      try {        pstmt.close();      } catch (SQLException ignored) {      }    }  }}// Display the given Image on a Swing framepublic void showImage(final Image img) {  Jframe frame = new Jframe("Image");  frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);  frame.setSize(img.getWidth(), img.getHeight());  frame.add(new JPanel() {    public void paint(Graphics g) {      g.drawImage(img, 0, 0, null);    }  });  frame.show();}

可能为您工作。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5565343.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存