I am trying to write a simple Java program to extract the tables and columns from Access databases. Using the Jackcess cookbook I've got the following:
String sourceDatabase = "C:\\temp\\test1.mdb";
Database accessDB = DatabaseBuilder.open(new File(sourceDatabase));
// Loop through the tables
Set<String> accessTables = accessDB.getTableNames();
for (String currentTable: accessTables) {
System.out.println("Reading table " + currentTable + "...");
Table table = accessDB.getTable(currentTable); // This is line 51 where the stacktrace occurs
// Loop through columns in current table
for(Column column : table.getColumns()) {
String columnName = column.getName();
Integer colType = column.getSQLType();
Boolean isAutoNumber = column.isAutoNumber();
System.out.println("\t" + columnName + " \t" + sqlTypeToText(colType) + "\t" + isAutoNumber);
}
System.out.println("");
}
accessDB.close();
However when I try to run it I get the following output with stacktrace:
Reading table _OracletblColumn...
colid 8 false
tblid 8 false
colname 12 false
dbid 8 false
Reading table _OracletblDatabase...
dbid 8 false
dbname 12 false
dbpathname 12 false
Reading table _OracletblTable...
tblid 8 false
dbid 8 false
tblname 12 false
Reading table DICT_ACCOM...
java.io.IOException: The specified network name is no longer available
at sun.nio.ch.FileDispatcher.pread0(Native Method)
at sun.nio.ch.FileDispatcher.pread(FileDispatcher.java:35)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:195)
at sun.nio.ch.IOUtil.read(IOUtil.java:171)
at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:612)
at com.healthmarketscience.jackcess.impl.PageChannel.readPage(PageChannel.java:211)
at com.healthmarketscience.jackcess.impl.TempPageHolder.setPage(TempPageHolder.java:86)
at com.healthmarketscience.jackcess.impl.TempPageHolder.setPage(TempPageHolder.java:74)
at com.healthmarketscience.jackcess.impl.UsageMap$ReferenceHandler.<init>(UsageMap.java:693)
at com.healthmarketscience.jackcess.impl.UsageMap$ReferenceHandler.<init>(UsageMap.java:673)
at com.healthmarketscience.jackcess.impl.UsageMap.initHandler(UsageMap.java:146)
at com.healthmarketscience.jackcess.impl.UsageMap.read(UsageMap.java:136)
at com.healthmarketscience.jackcess.impl.UsageMap.read(UsageMap.java:108)
at com.healthmarketscience.jackcess.impl.TableImpl.<init>(TableImpl.java:245)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.readTable(DatabaseImpl.java:1538)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.readSystemCatalog(DatabaseImpl.java:849)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.<init>(DatabaseImpl.java:526)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.open(DatabaseImpl.java:393)
at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:252)
at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:291)
at com.healthmarketscience.jackcess.util.LinkResolver$1.resolveLinkedDatabase(LinkResolver.java:42)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.getTable(DatabaseImpl.java:1003)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.getTable(DatabaseImpl.java:971)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.getTable(DatabaseImpl.java:929)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.getTable(DatabaseImpl.java:82)
at com.ralph.sql.test1.migrateTableDefs(test1.java:51)
at com.ralph.sql.test1.main(test1.java:24)
I've tried googling but haven't found anyone else having the same problem with Jackcess, what am I doing wrong?
On further investigation discovered the code above is not at fault.
When I moved the Access database to a different folder the code above works perfectly without stacktracing. My first thought was file permissions, I checked my user had read/write access to the database (and the C:\temp folder) which it did.
Turned out it was my corporate virus scan (McAfee) doing some sort of on access scan that was breaking it. As I am not allowed to disable the virus scanner, I'm going to move all my work into folders inside C:\users\username as the virus scan allows me to access these. So much for having local admin permission, it didn't help.