Search code examples
javaimagepostgresqlinputstreamimageicon

how to create a path to a picture taken from a database and saved a folder?


I'm trying to grab an image from a database in postgresql using java and I would like to know how to create a named route for that image (example C: /images/pic.png) ,this is how I take the image from the database.

InputStream is;
ImageIcon foto;
is =  results.getBinaryStream(i+1);
BufferedImage bi = ImageIO.read(is);
foto = new ImageIcon(bi);
Image img = foto.getImage();
Image newimg = img.getScaledInstance(140, 170, java.awt.Image.SCALE_SMOOTH);
ImageIcon newicon = new ImageIcon(newimg);

Thanks.


Solution

  • How does the images / pictures saved to the database? are you using another script for that? or are you manually saving it? I suggest that you should dedicate another column just for the path or location so that you could just refer to it in the future. Whenever you upload / save the photo, include the information you need in that column.

    This answer may also help you.