This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
each image would be a separate request, hence you'd take the image ID from the request and put it in the SQL query. I'd recommend using a PreparedStatement when using input from the request in SQL to guard against SQL Injection.
Common mistake: what you want is an HTML page that creates an HTML 'img' tag for each image, then each image results in a separate request to the image servlet and passes the specific ID, then the image servlet responds to each image image request with the image.
The other way would be to send a sing;le request and join the images together, but that is an image manipulation question, not a servlet question
It seems you do not have a deep understanding of how the web works. Start by examining the HTML source of a web page that contains multiple images. Then use an HTTP monitor (like the Firefox extension LiveHttpHeaders) to observe how that page is loaded, and in particular, how the HTML is accessed first, and then multiple requests for each of the images is sent. Also be sure to investigate the connection between the IMG tags Dave mentioned and the URLs being accessed on the server. Once you have a handle on all that you're in a position to make progress with the implementation; before that time you will struggle.