jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes Saving images in database from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Saving images in database from servlet" Watch "Saving images in database from servlet" New topic
Author

Saving images in database from servlet

niku shah
Ranch Hand

Joined: Aug 28, 2006
Posts: 41
Hi

I am developing a shopping cart webapp , i want to know that ,

how to add image in database using servlet as i want to insert images for various products ..

Thanks

Nikesh Shah
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

So which part are you having an issue with? The servelt part or the JDBC part? If it's the latter, then I'll move this to the JDBC forum. Let us know.


GenRocket - Experts at Building Test Data
niku shah
Ranch Hand

Joined: Aug 28, 2006
Posts: 41
Hi

Actually i have issue with both the parts servlets and jdbc....

would it require any file uploading code or just JDBC insert statement ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61232
    
  66

We can't guess what it is you need to you. Please be detailed in your posts.

Where is the image file coming from?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

would it require any file uploading code or just JDBC insert statement ?


It seems you are not clear about the technology. Since you are a gujarati would like to give some details.

File uploading is different then JDBC insert statement.
File upload gives you data in binary stream.
For storing image in database your database should support blob type.
Moreover it is not advisable to store many images in database, best solution is to store it in a file system(ie. on your machine) and store the path detail in DB.

For file uploading and storing in the database you can use struts framework instead of writing everything by using servlet.

Hope this helps.
Sunil Kumar Jakkaraju
Greenhorn

Joined: Oct 06, 2006
Posts: 24
As Jignesh pointed out, it is not advisable to store image files in database, especially if you are using those images to be rendered on your web applications.

It is better to use a file system and refer to it. It will also be easier to modify the images. It will be more manegable if you want different images to be displayed for specific locales / user groups.

However, if you are allowing the user to upload files to your webapp, then you might need some secure file system to store it. Your webapp may either create a sub directory under that file system for each user or store all the files in the same location.


Thanks & regards,
Sunil
When all else fails, follow instructions. - Allen's Axiom
niku shah
Ranch Hand

Joined: Aug 28, 2006
Posts: 41
Thank you all for the above responses...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving images in database from servlet