views:

122

answers:

3

I am creating a website as a mini project which will be used to sell various products. In the website i intend to give detailed info about the products which will be retrieved from the database. I am using Servlets and JSP as the serverside and pointbase DB. So i'll be using JDBC to connect to the DB. Please tell me how insert images into the DB and give sample code for the same. Also give details how to retrieve them.

Thanks you all in advance..

+7  A: 

Wouldn't it be easier to store images on a file system and store the paths in the database?

PolyThinker
@PolyThinker: As I'm wondering something similar as Shahensha, could you please elaborate a little more? Do you mean the same thing as NullUserException's option? (+1 at the ready) (EDIT: Actually, I'm pretty sure you do... +1)
Justian Meyer
I don't think there's much to elaborate on. You store the images on the server and just keep the paths to them in the database. Whenever you need to display an image, you read the path from to it the database and serve the file from the file system.
the_void
+2  A: 

You can insert binary data into databases that support binary fields (usually called BLOB).

But that isn't such a great idea - store them in your server and store the path to them on the database instead.

NullUserException
A: 

You should convert the file to a BLOB and then store it in the database as such, this will then make easy retrieval details below...

http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/exercises/BLOBPut/help.html

david99world