This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Accessing image from ms-access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Accessing image from ms-access" Watch "Accessing image from ms-access" New topic
Author

Accessing image from ms-access

Afroz Khan
Ranch Hand

Joined: Aug 07, 2000
Posts: 105
Hi
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;
while(rs.next())
{
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((c=is.read(buffer)) != -1)
{
f.write(buffer, 0,c);
}
is.close();
f.close();
count=count+1;
}
rs.close();
con.close();
===========
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
Thanks
Afroz


Afroz
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing image from ms-access
 
Similar Threads
Retrieving image from access database
Accessing Image from ms-access
About InputStream
Help me to Display multiple Images from Database using Servlets /JSP
URGENT: Accessing OLE object using java