Solved

Storing & Loading an image from Databse ??

Posted on 2001-06-15
7
188 Views
Last Modified: 2010-03-31
I have done this database application using a Java Application.What I'm using is the JDBC-ODBC Bridge...
Everything goes ok !! but can somebody tell me now I can store & Load an Image from it..
by the way I'm using MS ACCESS as the DBMS !!

Thanks !!
--Din---
0
Comment
Question by:dineth
7 Comments
 
LVL 3

Expert Comment

by:Sendoh
ID: 6194222
listening.....
btw, why not considering storing the image filename instead of the whole file...
cuz ms access is not efficient on that...:)
0
 

Author Comment

by:dineth
ID: 6194230
I can use the filename no prob !! but I wanna know whether storing an image is possible !! If ACCESS is not effient can I use MSSQL Server ??
0
 
LVL 3

Expert Comment

by:Sendoh
ID: 6194255
thats why i'm listening...:P
think it is possible but hard to implement...:P
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 6

Expert Comment

by:jaspreet_bajaj
ID: 6194290
hi
i think it is better to store the name of image and path
but i don't find it possible to do what you asked....
jaspreet
0
 
LVL 3

Expert Comment

by:rjackman
ID: 6194292
yes u can store the image in the access using binary format
for that u should have the Data Type as OLE Object.
convert the image to BinaryStream using InputStreams
then use the setBlob()
method of the Resultset to store the binary stream
Cheers
Rj
0
 
LVL 9

Accepted Solution

by:
yongsing earned 200 total points
ID: 6194380
Here is how you store an image into a database: You create a BLOB column in your table. This is for your image. Assuming that your table has only two columns: one an ID of the image, and the other the image.

PreparedStatement preparedStatement = connection.prepareStatement("insert into mytable (id, image) values (?, ?)"

// Set the value of the image ID
preparedStatement.setInt(1, 123);

// Get the image from a file, "someimage.jpg"
InputStream inputStream = new BufferedInputStream(new FileInputStream("someimage.jpg"));

preparedStatement.setBinaryStream(2, inputStream, inputStream.available());
preparedStatement.executeUpdate();
preparedStatement.close();
inputStream.close();


Here is how you retrieve the image from the database and store it into a file called "myimage.jpg":

ResultSet resultSet = statement.executeQuery("select image from myTable where id=123");
InputStream inputStream = new BufferedInputStream(resultSet.getBinaryStream(1));
OutputStream outputStream = new BufferedOutputStream(new FileOutputStream("myimage.jpg"));
int b = -1;
while ((b = inputStream.read()) != -1) outputStream.write(b);
inputStream.close();
outputStream.close();
0
 

Author Comment

by:dineth
ID: 6194570
Thanks guys !! for all the help !!
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 85
Weekend adv creator 3 39
Configure a Bean in an XML file 4 32
JAVA API design with micro service cloud in mind 1 18
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question