I am working on a web application, using JSP and Servlets, I was retreiving pictures as a string which contains the path of that picture.
while(rset.next())
{ %>
<img src='<%rset.getString(1)%>' />
<% }
And the table in the database would be like this.
id ---- image_path
1.....images/aaa.png
2.....images/bbb.png
So what I’m doing here is actually getting the path of the image, not the image itself, the images are inside a folder called images.
But later on, I found another way which actually stores images in a database.
PreparedStatement ps = con.prepareStatement("INSERT INTO pictures VALUES(?,?)");
File file = new File("C:/apache-tomcat-6.0.16/webapps/CodingDiaryExample/images/5.jpg");
FileInputStream fs = new FileInputStream(file);
ps.setInt(1,8);
ps.setBinaryStream(2,fs,fs.available());
int i = ps.executeUpdate();
Which is the best approach?
Getting images from Web Application is Good compared with fetching from Database.
OR if you have more number of images,then store in a FTP and fetch based on pah.