how should i retrieve my images that i stored in column having Attachment datatype in access 2007 in my java program??

Dani AI

Generated

Short, practical clarification for (and thanks to for the OLE pointers): the Access 2007 Attachment data type is a “complex” field that can hold one or more files (with filename and binary) per record. It is not the same as the older OLE Object wrapper, so code that only strips OLE headers will not directly apply.

Two reliable Java approaches:

  • Use Jackcess (pure Java). Jackcess understands ACCDB attachment columns and exposes each cell’s attachments as file entries (name + binary). Workflow: open the .accdb, get the table, iterate rows, read the attachment list for the column, and write each attachment stream to disk. See the Jackcess project for the library and docs: .

  • Use UCanAccess (JDBC). UCanAccess sits on top of Jackcess and gives a JDBC interface. It maps Access types to JDBC types so you can query the table and fetch the attachment column as a binary stream or byte array. See: .

Conceptual Jackcess flow (pseudo-code):

Database db = DatabaseBuilder.open(new File("my.accdb"));
Table t = db.getTable("MyTable");
for (Row r : t) {
  List attachments = (List) r.get("MyAttachmentColumn");
  for (Object a : attachments) {
    InputStream in = /* read attachment binary from a */;
    String name = /* read filename from a */;
    Files.copy(in, Paths.get("output", name), REPLACE_EXISTING);
  }
}
db.close();

Troubleshooting / cautions:

  • If the field was actually OLE Object (not Attachment) you will see an OLE wrapper; extracting the original file then needs OLE-stripping or a Windows DAO approach.
  • Attachments can contain multiple files per cell; handle lists.
  • For password-protected or encrypted ACCDBs supply credentials to the library/driver.
  • Close streams and the DB to avoid locks and resource leaks.

This approach is cross-platform (Jackcess/UCanAccess) and avoids Windows-only COM/DAO work unless you need DAO-specific behavior.

Recommended Answers

All 2 Replies

Hopefully this or this should help, but they store image as OLE, so I don't know how much it answers your question.

Hopefully this or this should help, but they store image as OLE, so I don't know how much it answers your question.

thanks for your help
i have stored images in attachment datatype it will be very helpful if u could suggest a way to retrive them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.