Reputation: 646
As i am developing the web application in J2EE, i have to be very careful about the database calls.
I am storing the images in database(BLOB).
For accessing those images, i created a servlet file.
I am passing id to that file as GET
method.
For showing the image, i needs to call that servlet file.
But as that servlet file making another database call, which i am most concern.
For example:
If in that particular jsp file, i wants to show 3 rows, i will make 1 call to show those rows AND another 3 calls for showing those images.
I have 2 options
But for me both are not good. Please suggest somethings.
Upvotes: 0
Views: 504
Reputation: 127
Instead of hitting the database so many times. Just write a query where you get all the rows which you need or images which you need. And display All the rows of images using ArrayList This would be a much easier method :)
Upvotes: 0
Reputation: 691635
If you're concerned about the load imposed to your database, you should probably avoid storing images in it. Instead, store the images on the disk, and store their path in the database.
This way, when you need to display three images in a single page, you execute a single query to get the paths of the three images, and you generate an HTML page containing the 3 paths.
If you have no other choice than storing the images as blobs in the database, and if you have load-tested your application, and showed that getting them from the database caused a significant performance problem, then consider using some application cache (like EHCache), to remove load from the database. You could also get the three images at once from the database and store them in the session, but you would have to find a way to cleanup the session, else the memory of your app would climb very fast.
Upvotes: 3