就像是:
// 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();}
可能为您工作。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)