Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Read image from the database for the given ID, then convert to BufferedImage */
- public BufferedImage readImage(String id) {
- BufferedImage bufImg = null;
- try {
- PreparedStatement pst = conn.prepareStatement("SELECT photo FROM vehicles WHERE veh_reg_no = ?");
- pst.setString(1, id);
- System.out.println(pst);
- ResultSet rset = pstmt.executeQuery();
- // Only one result expected
- rset.next();
- // Read image via InputStream
- InputStream in = rset.getBinaryStream("photo");
- // Decode the inputstream as BufferedImage
- bufImg = ImageIO.read(in);
- } catch(Exception e) {
- e.printStackTrace();
- }
- return bufImg;
- }
Advertisement
Add Comment
Please, Sign In to add comment