Solved

Storing & Loading an image from Databse ??

Posted on 2001-06-15
7
183 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Core Java. What output will be and why ? 6 66
micro services vs rest web services 16 87
tomcat not starting 6 32
configure dependency in POM for new database 3 17
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

862 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now