wood burning stoves 2.0
The moose likes JDBC and Relational Databases and the fly likes storing images in database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "storing images in database" Watch "storing images in database" New topic

storing images in database

jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
how do we store gif images in sql server and how do we retrieve them?
is it useful to store images in the sql server.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

You can store images as a BLOB. You would get/set them using JDBC. There are methods for byte[], binary stream and blob.
There are some reasons for storing images in a database. But, if they are images that are part of a web page, you are often better off storing them on a web server.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

is it useful to store images in the sql server.
My 2 cents. It depends. If your application is image intensive meaning your application that depends on the Database is primarily an imaging storage/retreival app of some sort which would mean that the majority of the data in your database is going to be binary data, then sure. There are also ways to optimize performance on some DB's for image storage/retreival.
On the other hand, if you application is primarily data centric and just stores a few images here and there (I would say 60% data, 40% images or less) then storing images along side data in a Database can really hurt your performance. In this situation it would be best to store the images somewhere on the harddrive and simply store reference/location data in the database of where the image is located on disk.
Do you like how that really didn't answer your question?
As far as "how to.." I found this on Google. It should get you started.

GenRocket - Experts at Building Test Data
Jason Steele
Ranch Hand

Joined: Apr 25, 2003
Posts: 100
My two cents...with interest:
The two cents:
I have never been a fan of storing images in a database. Images can really hamper db performance and increase db size tremendously. IMHO, just store the location and filename in the image field like Gregg said and then use that to pull image from file location in your web project or app.

The interest:
Opinions are going to vary on this subject. Some will argue that it is better to store all record data in a centralized location. Others, like me, say that storing a reference to the image is worth the extra effort if it will improve performance. Most users do not know where data is stored, and for the most part don't care, as long as the data is accessible.

Good luck in your decision and I too probably did not help you. :roll:

An egg is a chicken's house!
I agree. Here's the link: http://aspose.com/file-tools
subject: storing images in database
It's not a secret anymore!