Solved

Storing & Loading an image from Databse ??

Posted on 2001-06-15
7
192 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 64
ejb example issues 3 55
SequenceInputStream example 3 22
Using jdbcTemplate.batchUpdate to improve INSERT performance 6 27
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 video teaches viewers about errors in exception handling.

730 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