The UCanAccess JDBC driver can extract files from an Attachment field in an Access database. For a table named [AttachmentsTable]
ID - AutoNumber, Primary Key
Description - Text(255)
Attachments - Attachment
The following code will extract all of the files in the [Attachments] field for the record where ID=1:
import java.io.File;
import java.sql.*;
import net.ucanaccess.complex.Attachment;
...
String dbFileSpec = "C:/Users/Public/AttachmentsDB.accdb";
String connStr = "jdbc:ucanaccess://" + dbFileSpec;
try (Connection conn = DriverManager.getConnection(connStr)) {
try (Statement s = conn.createStatement()) {
try (ResultSet rs = s.executeQuery(
"SELECT Attachments FROM AttachmentsTable WHERE ID=1")) {
rs.next();
// retrieve array of net.ucanaccess.complex.Attachment objects
Attachment[] atts = (Attachment[]) rs.getObject(1);
for (Attachment att : atts) {
System.out.println(att.getName());
org.apache.commons.io.FileUtils.writeByteArrayToFile(
new File("C:/Users/Gord/Desktop/" + att.getName()),
att.getData());
}
}
}
}
For more information on using the UCanAccess JDBC driver see
Manipulating an Access database from Java without ODBC