Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving a jpeg to MS Access

 
Trevor Pereira
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All, I am trying to save a jpeg to a OLE field in a MS Access DB. Retreiving the image as an array of bytes does not work...see code below
public void retrieveData(com.borland.dx.sql.dataset.Database aDB){
Connection conn = aDB.getJdbcConnection();
String sql = "SELECT * FROM Videos";
try{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
VideoDataModel tmpDM = new VideoDataModel();
tmpDM.setId(rs.getInt("ID"));
tmpDM.setStrMovieName(rs.getString("VideoName"));
tmpDM.setStrMoviePrice(rs.getString("VideoPrice"));
tmpDM.setStrMovieRating(rs.getString("VideoRating"));
tmpDM.setMovieImage(new ImageIcon(rs.getBytes("VideoPicture")));
tmpArray.add(tmpDM);
}//end loop
}catch(Exception e){
System.out.println(e.getMessage());
}
}//end retrieve data
I guess I could just save the path of where the image was saved on the user's computer, but I just wanted to see if any of you have a solution.
If I was using DB2 or Oracle there are datatypes in the new JDBC API to handle a BLOB, but is there a match for an OLE Object?
Curious,
Trevor
 
Kevin Mukhar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Trevor P:
Hi All, I am trying to save a jpeg to a OLE field in a MS Access DB. Retreiving the image as an array of bytes does not work...see code below
tmpDM.setMovieImage(new ImageIcon(rs.getBytes("VideoPicture")));
tmpArray.add(tmpDM);

The code above will work as long as the value in the VideoPicture column is truly an array of bytes from a JPG (or some other supported graphic format). However, because you say that the field is an OLE field in an Access database, my first guess would be that the OLE field has more data in it than just the jpg bytes, because an OLE object can be more than just a jpg.
(By the way, when one says that something doesn't work, it often helps to include the evidence that shows that it doesn't work: stack trace, debug output, etc.)

If I was using DB2 or Oracle there are datatypes in the new JDBC API to handle a BLOB, but is there a match for an OLE Object?

No. BLOB is an official SQL standard datatype, so JDBC provides support for BLOBs, CLOBs, etc. OLE Objects are Microsoft specific features that are not part of the SQL standard, so the JDBC standard does not provide direct support for OLE objects.
There might be driver specific support for OLE objects. That is, by using a driver specific class or method (not part of the JDBC standard) a particular driver may provide support for OLE objects. Or, you might be able to use one of the other JDBC types, such as BLOB, Object, byte[], or Ref.
 
Trevor Pereira
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Kevin, I guess if I am to use MSAccess I will just store the path of the saved JPEG.
I guess I should have been more specific when I said that "the code does not work". In actually there is co error output...no exception is thrown. Your info about more information being in OLE object than just bytes is probally the reason that no picture shows up as the labels icon.
Thanks again for your help.
Trevor
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic