This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Retrieving image from access database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Retrieving image from access database" Watch "Retrieving image from access database" New topic

Retrieving image from access database

Afroz Khan
Ranch Hand

Joined: Aug 07, 2000
Posts: 105
Here is my code for accessing the image from the access database, stored in OLE object field:
PreparedStatement stmt =con.prepareStatement("select picture from picturefile");
rs = stmt.executeQuery ();
int length=0;
int count=1;
InputStream is=rs.getBinaryStream(1);
String s="c:"+File.separator+"test"+File.separator+count+".gif";
FileOutputStream f=new FileOutputStream(s);
int c;
byte buffer[]=new byte[1024];
while(( != -1)
f.write(buffer, 0,c);
The above code is generating files from the database and storing in hard disk, but when i open any file, its opening as blank.
Can anyone tell me how to access the images from the access db and store it in harddisk, and how to check for the image format whether its jpg or gif or bmp

I agree. Here's the link:
subject: Retrieving image from access database
jQuery in Action, 3rd edition