Solved

Storing & Loading an image from Databse ??

Posted on 2001-06-15
7
181 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumHeights2  challenge 7 76
Receive file in Servlet 1 36
factorial example challenge 10 62
powerN  challenge 3 47
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

757 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

18 Experts available now in Live!

Get 1:1 Help Now