Ragnar
Ragnar

Reputation: 665

Opening an Access database file using Jackcess

I am using the Jackcess API to copy my database to into a file. I successfully establish a connection to my database but when I try to open the database I get a null pointer exception.

My code

File tempTarget=File.createTempFile("eap-mirror", "eap");     
String conString = EaDbStringParser.eaDbStringToJdbc(sourceString);
this.source=DriverManager.getConnection(conString);
this.source.setReadOnly(true);
try {
    FileUtils.copyFile(new File(templateFileString), tempTarget);
    System.out.println("file copied");
} catch (IOException e) {
    e.printStackTrace();
}

this.target=Database.open(tempTarget,false,false); //Cannot run this line

I am not able to run Database.open method and hence the target is null which throws the exception.

Anyone having any idea what I am doing wrong or what is required here?

Thanks

Upvotes: 1

Views: 923

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123839

com.healthmarketscience.jackcess.Database has no .open method (ref: here). To open a database file in Jackcess we use DatabaseBuilder.open, as in

this.target = DatabaseBuilder.open(tempTarget);

Edit:

I see from another question that you are trying to use a rather old 1.x version of Jackcess (1.2.6) that did offer an .open method for a Database object. You really should consider using a more current 2.x version of Jackcess.

Upvotes: 1

Related Questions