Click here to Skip to main content
15,888,177 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

At the moment I have a Microsoft Access database with an OLE Object holding a picture.
I have tried to find code to retrieve the image saved in the OLE Object but to no success.

If there is anyone that can help me with this?

Regards
Mitchell
Posted
Comments
M.R. Inc 27-Jul-12 7:50am    
This is what I have so far but it is outputting NULL after '4'
With a 'java.lang.NullPointerException'

InputStream binaryStream = rs.getBinaryStream("PIC");
Image img = ImageIO.read(binaryStream);
System.out.println("4");
if(img == null)
{
System.out.println("NULL");
}
ImageIcon ico = new ImageIcon(img);
System.out.println("5");
jLabel7.setIcon(ico);

Any help with this code would be helpful.

Regards
Mitchell
Richard MacCutchan 27-Jul-12 8:10am    
Well I couldn't swear to this but I have suspicion that the variable img is NULL. I would suggest you spend some time with your debugger to find out what happens when you try to get the image stream.
M.R. Inc 27-Jul-12 8:17am    
Okay, BinaryStream has a value of #2694 when it reaches '4'
but img is always null.

So maybe there is a different way I must read from the binary stream?

Regards
Mitchell
Richard MacCutchan 27-Jul-12 8:30am    
BinaryStream has a value of #2694
Which means what? You need to investigate why the call to ImageIO.read() does not return a valid image, which may be because the stream is not valid, or any number of other reasons.
M.R. Inc 27-Jul-12 9:47am    
Okay so far I cannot get anything to work.

Do you have any other ideas on reading the OLE Object? (Its a picture in the MS Access Database)

Regards
Mitchell

1 solution

There is a quite a bit of difference between using OLE in java and getting an OLE object from a MS Access database via Java.

Normally MS Access is accessed via the appropriate ODBC driver (which has nothing to do with java.) And ODBC does not support OLE objects directly. At least not as far as I recall nor that I can find.

So what one must do is exact the OLE in binary and then exact information from that by manipulating it. In other words the binary extracted contains a image and OTHER information. That other information be removed before the binary data will be an actual image.

Following provides some information.

http://stackoverflow.com/questions/1029340/extract-ole-object-pdf-from-access-db[^]

BEFORE attempting to manipulate the image you MUST test the following.
1. Write your code to extract the image from the object.
2. Write the binary data to a file.
3. Use an appropriate external application to load the file and insure the format is correct.
4. Repeat the above steps for all known variations
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900