Solved

Storing & Loading an image from Databse ??

Posted on 2001-06-15
7
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

688 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