UCanAccess seems unable to read OLE Object column using getBytes()





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I have a quite large .mdb access database I want to convert to SQLite3 to use it under Linux.



I am unable to transfer any of the BLOBs (mostly containing images) I have.
Here is a sample test program:



import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class prova {
public static void main(String args) {
String url = "jdbc:ucanaccess://data/BookDB-201810.mdb";
try {
Connection c = DriverManager.getConnection(url);
PreparedStatement ps;
ResultSet rs;
String q = "SELECT * FROM PersonImage";
ps = c.prepareStatement(q);
rs = ps.executeQuery();
while (rs.next()) {
byte i = rs.getBytes("Image");
String fn = String.format("data/img/i%05d.%d.jpg", rs.getInt("PersonId"), rs.getInt("Index"));
try (FileOutputStream fos = new FileOutputStream(fn)) {
fos.write(i);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}


Program runs without errors, but the produced files are "strange" (surely not images):



$ ls -l i00072.1.jpg 
-rw-r--r-- 1 mcon mcon 369 Nov 23 11:38 i00072.1.jpg
$ file i00072.1.jpg
i00072.1.jpg: Java serialization data, version 5


Looking int them I find this:



....sr..net.ucanaccess.jdbc.BlobKey...........L.
columnNamet..Ljava/lang/String;L..keyt..Ljava/util/HashMap;L. tableNameq.~..xpt..Imagesr..java.util.HashMap......`....F.
loadFactorI. thresholdxp?@......w.........t..PersonIDsr..java.lang.Integer.⠤...8...I..valuexr..java.lang.Number...........xp...
Ht..Indexsr..java.lang.ShorthM7.4`.R...S..valuexq.~. ..xt..PersonImage


What am I doing wrong?



Update:
Since my aim is to convert a book database (maintained on the net as .mdb using the obsolete program BookCAT for historical reasons) I found AccessConverter which seems to fit the bill; unfortunately there are essentially two problems with that:




  • In my database some columns are named "Index", which is a reserved word for SQLite (and others, but apparently not for MS-Access); this is trivially fixed inserting a filter "Index" -> "Idx".

  • There is a translation switch (type) { case xxx: ... to convert the various MS-Access types to more conventional SQLite3 types; breakpointing on the default: label I discovered (as @ErikvonAsmuth correctly guessed) there are unhandled OLE types. I have no idea about how to handle those.


In the program (BookCAT) those fields contain two kind of data:




  • images

  • formatted text


The latter is less important because there's always a duplicate "plaintext" version (it would be nice to retrieve also the formatted version, but...).



I would really like to be able to extract the images, though.



In image data there is a companion "ImageType" column invariably set to "2" which (if I'm not mistaken) means they should be .jpeg images.



What can I do to retrieve OLE data in a usable format?



Note: AccessConverter does not use ucanaccess, it uses directly the underlying com.healthmarketscience.jackcess lib instead.



Note2: it seems BookCAT is built using Delphi, if that is relevant.










share|improve this question




















  • 1





    There's no such thing as a VARBINARY in Access. There are OLE objects, but those come in many types, some just containing a file as binary data, others containing specific headers, and others compressing files and putting multiple files in a single row. Unless you specify exactly what you're trying to import, we likely won't be able to help you.

    – Erik A
    Nov 23 '18 at 23:53











  • @ErikvonAsmuth: just a few minutes ago I discovered You are absolutely right. I will update Question to reflect my findings and refine question (short summary: those fields contain either images or "formatted text").

    – ZioByte
    Nov 24 '18 at 1:03


















2















I have a quite large .mdb access database I want to convert to SQLite3 to use it under Linux.



I am unable to transfer any of the BLOBs (mostly containing images) I have.
Here is a sample test program:



import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class prova {
public static void main(String args) {
String url = "jdbc:ucanaccess://data/BookDB-201810.mdb";
try {
Connection c = DriverManager.getConnection(url);
PreparedStatement ps;
ResultSet rs;
String q = "SELECT * FROM PersonImage";
ps = c.prepareStatement(q);
rs = ps.executeQuery();
while (rs.next()) {
byte i = rs.getBytes("Image");
String fn = String.format("data/img/i%05d.%d.jpg", rs.getInt("PersonId"), rs.getInt("Index"));
try (FileOutputStream fos = new FileOutputStream(fn)) {
fos.write(i);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}


Program runs without errors, but the produced files are "strange" (surely not images):



$ ls -l i00072.1.jpg 
-rw-r--r-- 1 mcon mcon 369 Nov 23 11:38 i00072.1.jpg
$ file i00072.1.jpg
i00072.1.jpg: Java serialization data, version 5


Looking int them I find this:



....sr..net.ucanaccess.jdbc.BlobKey...........L.
columnNamet..Ljava/lang/String;L..keyt..Ljava/util/HashMap;L. tableNameq.~..xpt..Imagesr..java.util.HashMap......`....F.
loadFactorI. thresholdxp?@......w.........t..PersonIDsr..java.lang.Integer.⠤...8...I..valuexr..java.lang.Number...........xp...
Ht..Indexsr..java.lang.ShorthM7.4`.R...S..valuexq.~. ..xt..PersonImage


What am I doing wrong?



Update:
Since my aim is to convert a book database (maintained on the net as .mdb using the obsolete program BookCAT for historical reasons) I found AccessConverter which seems to fit the bill; unfortunately there are essentially two problems with that:




  • In my database some columns are named "Index", which is a reserved word for SQLite (and others, but apparently not for MS-Access); this is trivially fixed inserting a filter "Index" -> "Idx".

  • There is a translation switch (type) { case xxx: ... to convert the various MS-Access types to more conventional SQLite3 types; breakpointing on the default: label I discovered (as @ErikvonAsmuth correctly guessed) there are unhandled OLE types. I have no idea about how to handle those.


In the program (BookCAT) those fields contain two kind of data:




  • images

  • formatted text


The latter is less important because there's always a duplicate "plaintext" version (it would be nice to retrieve also the formatted version, but...).



I would really like to be able to extract the images, though.



In image data there is a companion "ImageType" column invariably set to "2" which (if I'm not mistaken) means they should be .jpeg images.



What can I do to retrieve OLE data in a usable format?



Note: AccessConverter does not use ucanaccess, it uses directly the underlying com.healthmarketscience.jackcess lib instead.



Note2: it seems BookCAT is built using Delphi, if that is relevant.










share|improve this question




















  • 1





    There's no such thing as a VARBINARY in Access. There are OLE objects, but those come in many types, some just containing a file as binary data, others containing specific headers, and others compressing files and putting multiple files in a single row. Unless you specify exactly what you're trying to import, we likely won't be able to help you.

    – Erik A
    Nov 23 '18 at 23:53











  • @ErikvonAsmuth: just a few minutes ago I discovered You are absolutely right. I will update Question to reflect my findings and refine question (short summary: those fields contain either images or "formatted text").

    – ZioByte
    Nov 24 '18 at 1:03














2












2








2








I have a quite large .mdb access database I want to convert to SQLite3 to use it under Linux.



I am unable to transfer any of the BLOBs (mostly containing images) I have.
Here is a sample test program:



import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class prova {
public static void main(String args) {
String url = "jdbc:ucanaccess://data/BookDB-201810.mdb";
try {
Connection c = DriverManager.getConnection(url);
PreparedStatement ps;
ResultSet rs;
String q = "SELECT * FROM PersonImage";
ps = c.prepareStatement(q);
rs = ps.executeQuery();
while (rs.next()) {
byte i = rs.getBytes("Image");
String fn = String.format("data/img/i%05d.%d.jpg", rs.getInt("PersonId"), rs.getInt("Index"));
try (FileOutputStream fos = new FileOutputStream(fn)) {
fos.write(i);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}


Program runs without errors, but the produced files are "strange" (surely not images):



$ ls -l i00072.1.jpg 
-rw-r--r-- 1 mcon mcon 369 Nov 23 11:38 i00072.1.jpg
$ file i00072.1.jpg
i00072.1.jpg: Java serialization data, version 5


Looking int them I find this:



....sr..net.ucanaccess.jdbc.BlobKey...........L.
columnNamet..Ljava/lang/String;L..keyt..Ljava/util/HashMap;L. tableNameq.~..xpt..Imagesr..java.util.HashMap......`....F.
loadFactorI. thresholdxp?@......w.........t..PersonIDsr..java.lang.Integer.⠤...8...I..valuexr..java.lang.Number...........xp...
Ht..Indexsr..java.lang.ShorthM7.4`.R...S..valuexq.~. ..xt..PersonImage


What am I doing wrong?



Update:
Since my aim is to convert a book database (maintained on the net as .mdb using the obsolete program BookCAT for historical reasons) I found AccessConverter which seems to fit the bill; unfortunately there are essentially two problems with that:




  • In my database some columns are named "Index", which is a reserved word for SQLite (and others, but apparently not for MS-Access); this is trivially fixed inserting a filter "Index" -> "Idx".

  • There is a translation switch (type) { case xxx: ... to convert the various MS-Access types to more conventional SQLite3 types; breakpointing on the default: label I discovered (as @ErikvonAsmuth correctly guessed) there are unhandled OLE types. I have no idea about how to handle those.


In the program (BookCAT) those fields contain two kind of data:




  • images

  • formatted text


The latter is less important because there's always a duplicate "plaintext" version (it would be nice to retrieve also the formatted version, but...).



I would really like to be able to extract the images, though.



In image data there is a companion "ImageType" column invariably set to "2" which (if I'm not mistaken) means they should be .jpeg images.



What can I do to retrieve OLE data in a usable format?



Note: AccessConverter does not use ucanaccess, it uses directly the underlying com.healthmarketscience.jackcess lib instead.



Note2: it seems BookCAT is built using Delphi, if that is relevant.










share|improve this question
















I have a quite large .mdb access database I want to convert to SQLite3 to use it under Linux.



I am unable to transfer any of the BLOBs (mostly containing images) I have.
Here is a sample test program:



import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class prova {
public static void main(String args) {
String url = "jdbc:ucanaccess://data/BookDB-201810.mdb";
try {
Connection c = DriverManager.getConnection(url);
PreparedStatement ps;
ResultSet rs;
String q = "SELECT * FROM PersonImage";
ps = c.prepareStatement(q);
rs = ps.executeQuery();
while (rs.next()) {
byte i = rs.getBytes("Image");
String fn = String.format("data/img/i%05d.%d.jpg", rs.getInt("PersonId"), rs.getInt("Index"));
try (FileOutputStream fos = new FileOutputStream(fn)) {
fos.write(i);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}


Program runs without errors, but the produced files are "strange" (surely not images):



$ ls -l i00072.1.jpg 
-rw-r--r-- 1 mcon mcon 369 Nov 23 11:38 i00072.1.jpg
$ file i00072.1.jpg
i00072.1.jpg: Java serialization data, version 5


Looking int them I find this:



....sr..net.ucanaccess.jdbc.BlobKey...........L.
columnNamet..Ljava/lang/String;L..keyt..Ljava/util/HashMap;L. tableNameq.~..xpt..Imagesr..java.util.HashMap......`....F.
loadFactorI. thresholdxp?@......w.........t..PersonIDsr..java.lang.Integer.⠤...8...I..valuexr..java.lang.Number...........xp...
Ht..Indexsr..java.lang.ShorthM7.4`.R...S..valuexq.~. ..xt..PersonImage


What am I doing wrong?



Update:
Since my aim is to convert a book database (maintained on the net as .mdb using the obsolete program BookCAT for historical reasons) I found AccessConverter which seems to fit the bill; unfortunately there are essentially two problems with that:




  • In my database some columns are named "Index", which is a reserved word for SQLite (and others, but apparently not for MS-Access); this is trivially fixed inserting a filter "Index" -> "Idx".

  • There is a translation switch (type) { case xxx: ... to convert the various MS-Access types to more conventional SQLite3 types; breakpointing on the default: label I discovered (as @ErikvonAsmuth correctly guessed) there are unhandled OLE types. I have no idea about how to handle those.


In the program (BookCAT) those fields contain two kind of data:




  • images

  • formatted text


The latter is less important because there's always a duplicate "plaintext" version (it would be nice to retrieve also the formatted version, but...).



I would really like to be able to extract the images, though.



In image data there is a companion "ImageType" column invariably set to "2" which (if I'm not mistaken) means they should be .jpeg images.



What can I do to retrieve OLE data in a usable format?



Note: AccessConverter does not use ucanaccess, it uses directly the underlying com.healthmarketscience.jackcess lib instead.



Note2: it seems BookCAT is built using Delphi, if that is relevant.







java ms-access jdbc ucanaccess jackcess






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 16:17









Gord Thompson

79.1k1498226




79.1k1498226










asked Nov 23 '18 at 19:21









ZioByteZioByte

8241030




8241030








  • 1





    There's no such thing as a VARBINARY in Access. There are OLE objects, but those come in many types, some just containing a file as binary data, others containing specific headers, and others compressing files and putting multiple files in a single row. Unless you specify exactly what you're trying to import, we likely won't be able to help you.

    – Erik A
    Nov 23 '18 at 23:53











  • @ErikvonAsmuth: just a few minutes ago I discovered You are absolutely right. I will update Question to reflect my findings and refine question (short summary: those fields contain either images or "formatted text").

    – ZioByte
    Nov 24 '18 at 1:03














  • 1





    There's no such thing as a VARBINARY in Access. There are OLE objects, but those come in many types, some just containing a file as binary data, others containing specific headers, and others compressing files and putting multiple files in a single row. Unless you specify exactly what you're trying to import, we likely won't be able to help you.

    – Erik A
    Nov 23 '18 at 23:53











  • @ErikvonAsmuth: just a few minutes ago I discovered You are absolutely right. I will update Question to reflect my findings and refine question (short summary: those fields contain either images or "formatted text").

    – ZioByte
    Nov 24 '18 at 1:03








1




1





There's no such thing as a VARBINARY in Access. There are OLE objects, but those come in many types, some just containing a file as binary data, others containing specific headers, and others compressing files and putting multiple files in a single row. Unless you specify exactly what you're trying to import, we likely won't be able to help you.

– Erik A
Nov 23 '18 at 23:53





There's no such thing as a VARBINARY in Access. There are OLE objects, but those come in many types, some just containing a file as binary data, others containing specific headers, and others compressing files and putting multiple files in a single row. Unless you specify exactly what you're trying to import, we likely won't be able to help you.

– Erik A
Nov 23 '18 at 23:53













@ErikvonAsmuth: just a few minutes ago I discovered You are absolutely right. I will update Question to reflect my findings and refine question (short summary: those fields contain either images or "formatted text").

– ZioByte
Nov 24 '18 at 1:03





@ErikvonAsmuth: just a few minutes ago I discovered You are absolutely right. I will update Question to reflect my findings and refine question (short summary: those fields contain either images or "formatted text").

– ZioByte
Nov 24 '18 at 1:03












2 Answers
2






active

oldest

votes


















1














It turns out that, in my specific case, all "OLE" fields are actually BLOBs, unrecognizable as OLE2 objects.



In this condition jackcess returns a Enum OleBlob.ContentType.UNKNOWN Type and, in this case, it will refuse to access BLOB content (OleBlob.content.getBytes() returns null).



In order to access stored data is necessary to use directly Column.getBytes(name) (completely bypassing OLE subsystem).



Why, in this condition, ucanaccess returns an invalid value, instead of failure, is beyond me (probably I should file a bug report; comments welcome).



Image data is plain jpeg-formatted file, while the "formatted text" seems some custom serialization of Delphi TRichText widget I don't know how to parse, but that is another issue.



Using jackcess Column.getBytes(name) I was able to retrieve the data I needed.






share|improve this answer































    1














    With UCanAccess you need to use ResultSet#getBlob:



    String q = "SELECT * FROM PersonImage";
    ps = conn.prepareStatement(q);
    rs = ps.executeQuery();
    while (rs.next()) {
    java.sql.Blob image = rs.getBlob("Image");
    String fn = String.format("C:/Users/Gord/Pictures/i%05d.%d.jpg", rs.getInt("PersonId"), rs.getInt("Index"));
    try (FileOutputStream fos = new FileOutputStream(fn)) {
    fos.write(image.getBytes(1, (int) image.length()));
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }





    share|improve this answer


























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451986%2fucanaccess-seems-unable-to-read-ole-object-column-using-getbytes%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      It turns out that, in my specific case, all "OLE" fields are actually BLOBs, unrecognizable as OLE2 objects.



      In this condition jackcess returns a Enum OleBlob.ContentType.UNKNOWN Type and, in this case, it will refuse to access BLOB content (OleBlob.content.getBytes() returns null).



      In order to access stored data is necessary to use directly Column.getBytes(name) (completely bypassing OLE subsystem).



      Why, in this condition, ucanaccess returns an invalid value, instead of failure, is beyond me (probably I should file a bug report; comments welcome).



      Image data is plain jpeg-formatted file, while the "formatted text" seems some custom serialization of Delphi TRichText widget I don't know how to parse, but that is another issue.



      Using jackcess Column.getBytes(name) I was able to retrieve the data I needed.






      share|improve this answer




























        1














        It turns out that, in my specific case, all "OLE" fields are actually BLOBs, unrecognizable as OLE2 objects.



        In this condition jackcess returns a Enum OleBlob.ContentType.UNKNOWN Type and, in this case, it will refuse to access BLOB content (OleBlob.content.getBytes() returns null).



        In order to access stored data is necessary to use directly Column.getBytes(name) (completely bypassing OLE subsystem).



        Why, in this condition, ucanaccess returns an invalid value, instead of failure, is beyond me (probably I should file a bug report; comments welcome).



        Image data is plain jpeg-formatted file, while the "formatted text" seems some custom serialization of Delphi TRichText widget I don't know how to parse, but that is another issue.



        Using jackcess Column.getBytes(name) I was able to retrieve the data I needed.






        share|improve this answer


























          1












          1








          1







          It turns out that, in my specific case, all "OLE" fields are actually BLOBs, unrecognizable as OLE2 objects.



          In this condition jackcess returns a Enum OleBlob.ContentType.UNKNOWN Type and, in this case, it will refuse to access BLOB content (OleBlob.content.getBytes() returns null).



          In order to access stored data is necessary to use directly Column.getBytes(name) (completely bypassing OLE subsystem).



          Why, in this condition, ucanaccess returns an invalid value, instead of failure, is beyond me (probably I should file a bug report; comments welcome).



          Image data is plain jpeg-formatted file, while the "formatted text" seems some custom serialization of Delphi TRichText widget I don't know how to parse, but that is another issue.



          Using jackcess Column.getBytes(name) I was able to retrieve the data I needed.






          share|improve this answer













          It turns out that, in my specific case, all "OLE" fields are actually BLOBs, unrecognizable as OLE2 objects.



          In this condition jackcess returns a Enum OleBlob.ContentType.UNKNOWN Type and, in this case, it will refuse to access BLOB content (OleBlob.content.getBytes() returns null).



          In order to access stored data is necessary to use directly Column.getBytes(name) (completely bypassing OLE subsystem).



          Why, in this condition, ucanaccess returns an invalid value, instead of failure, is beyond me (probably I should file a bug report; comments welcome).



          Image data is plain jpeg-formatted file, while the "formatted text" seems some custom serialization of Delphi TRichText widget I don't know how to parse, but that is another issue.



          Using jackcess Column.getBytes(name) I was able to retrieve the data I needed.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 17:08









          ZioByteZioByte

          8241030




          8241030

























              1














              With UCanAccess you need to use ResultSet#getBlob:



              String q = "SELECT * FROM PersonImage";
              ps = conn.prepareStatement(q);
              rs = ps.executeQuery();
              while (rs.next()) {
              java.sql.Blob image = rs.getBlob("Image");
              String fn = String.format("C:/Users/Gord/Pictures/i%05d.%d.jpg", rs.getInt("PersonId"), rs.getInt("Index"));
              try (FileOutputStream fos = new FileOutputStream(fn)) {
              fos.write(image.getBytes(1, (int) image.length()));
              } catch (FileNotFoundException e) {
              e.printStackTrace();
              } catch (IOException e) {
              e.printStackTrace();
              }
              }





              share|improve this answer






























                1














                With UCanAccess you need to use ResultSet#getBlob:



                String q = "SELECT * FROM PersonImage";
                ps = conn.prepareStatement(q);
                rs = ps.executeQuery();
                while (rs.next()) {
                java.sql.Blob image = rs.getBlob("Image");
                String fn = String.format("C:/Users/Gord/Pictures/i%05d.%d.jpg", rs.getInt("PersonId"), rs.getInt("Index"));
                try (FileOutputStream fos = new FileOutputStream(fn)) {
                fos.write(image.getBytes(1, (int) image.length()));
                } catch (FileNotFoundException e) {
                e.printStackTrace();
                } catch (IOException e) {
                e.printStackTrace();
                }
                }





                share|improve this answer




























                  1












                  1








                  1







                  With UCanAccess you need to use ResultSet#getBlob:



                  String q = "SELECT * FROM PersonImage";
                  ps = conn.prepareStatement(q);
                  rs = ps.executeQuery();
                  while (rs.next()) {
                  java.sql.Blob image = rs.getBlob("Image");
                  String fn = String.format("C:/Users/Gord/Pictures/i%05d.%d.jpg", rs.getInt("PersonId"), rs.getInt("Index"));
                  try (FileOutputStream fos = new FileOutputStream(fn)) {
                  fos.write(image.getBytes(1, (int) image.length()));
                  } catch (FileNotFoundException e) {
                  e.printStackTrace();
                  } catch (IOException e) {
                  e.printStackTrace();
                  }
                  }





                  share|improve this answer















                  With UCanAccess you need to use ResultSet#getBlob:



                  String q = "SELECT * FROM PersonImage";
                  ps = conn.prepareStatement(q);
                  rs = ps.executeQuery();
                  while (rs.next()) {
                  java.sql.Blob image = rs.getBlob("Image");
                  String fn = String.format("C:/Users/Gord/Pictures/i%05d.%d.jpg", rs.getInt("PersonId"), rs.getInt("Index"));
                  try (FileOutputStream fos = new FileOutputStream(fn)) {
                  fos.write(image.getBytes(1, (int) image.length()));
                  } catch (FileNotFoundException e) {
                  e.printStackTrace();
                  } catch (IOException e) {
                  e.printStackTrace();
                  }
                  }






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 26 '18 at 16:14

























                  answered Nov 26 '18 at 14:39









                  Gord ThompsonGord Thompson

                  79.1k1498226




                  79.1k1498226






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451986%2fucanaccess-seems-unable-to-read-ole-object-column-using-getbytes%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Xamarin.form Move up view when keyboard appear

                      Post-Redirect-Get with Spring WebFlux and Thymeleaf

                      Anylogic : not able to use stopDelay()