2015-04-23 42 views
1

我正在使用Jackcess API將我的數據庫複製到文件中。我成功地建立了連接到我的數據庫,但是當我嘗試打開數據庫時,我得到一個空指針異常。使用Jackcess打開Access數據庫文件

我的代碼

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 

我不能夠運行Database.open方法,因此目標爲null會拋出異常。

任何人有任何想法我做錯了什麼或在這裏需要什麼?

由於

+0

可能重複的[Jackcess DatabaseBuilder.open失敗](http://stackoverflow.com/questions/29844258/jackcess-databasebuilder-open-fails) –

回答

1

com.healthmarketscience.jackcess.Database沒有.open方法(參照here)。要打開Jackcess我們使用DatabaseBuilder.open數據庫文件,如

this.target = DatabaseBuilder.open(tempTarget); 

編輯:

我從another question您嘗試使用Jackcess的,而舊的1.x版本(1.2.6)見它確實爲數據庫對象提供了一個.open方法。你真的應該考慮使用更當前的2.x版本的Jackcess。

+0

但在eclipse中它提供了我的Database.open()方法並導入com.healthmarketscience.jackcess.Database; – wearybands

+0

在我的工作區中有一個maven項目,如果我從其工作的maven項目中調用此方法,並且如果我從插件項目中調用此方法,那麼它不起作用 – wearybands

+0

然後,必須是其他'Database'對象,而不是'com.healthmarketscience .jackcess.Database'接口。 –

相關問題