I am using Jackcess API in my Eclipse plugin project. I added jackcess-2.1.0.jar
file under resources/lib. I included the jar under my Binary build and in build.properties
. I successfully make a connection using connection string but my DatabaseBuilder.open()
call is not executing. My code is
public void run() {
try {
File tempTarget = File.createTempFile("eap-mirror", "eap");
try {
this.source = DriverManager.getConnection(EaDbStringParser.eaDbStringToJdbc(sourceString));
this.source.setReadOnly(true);
try {
FileUtils.copyFile(new File(templateFileString), tempTarget);
} catch (IOException e) {
e.printStackTrace();
}
// Changes
try {
this.target = DatabaseBuilder.open(tempTarget);
} catch (IOException e) {
e.printStackTrace();
}
Collection<String> tables = selectTables(source);
long time = System.currentTimeMillis();
for (String tableName : tables) {
long tTime = System.currentTimeMillis();
Table table = target.getTable(tableName);
System.out.print("Mirroring table " + tableName + "...");
table.setOverrideAutonumber(true);
copyTable(table, source, target);
System.out.println(" took "+ (System.currentTimeMillis() - tTime));
}
System.out.println("Done. Overall time: "+ (System.currentTimeMillis() - time));
System.out.println("done");
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// More Code here
} catch (IOException e1) {
}
}
When I run the class in debug mode and I reach DatabaseBuilder.open
call it fails.
Here is my project structure:
Can anyone tell me the possible reason for it ?
The
.open
method ofDatabaseBuilder
expects to open an existing well-formed Access database file. The.createTempFile
method ofjava.io.File
creates a 0-byte file. So, the codewill cause Jackcess to throw
when it tries to do
DatabaseBuilder.open(dbFile)
.Instead, you should
DatabaseBuilder.create
to convert the 0-byte file into a real Access database file like this