簡體   English   中英

如何將derby數據庫與build .jar文件一起使用?

[英]how can i use derby database with the build .jar file?

我在derby數據庫中使用Java。

當我在netbeans中啟動“ jdbc:derby”數據庫的連接並運行我的代碼時,該程序顯示出來,並且一切正常。

通過打開生成的“ .jar”文件,該程序將立即顯示並立即關閉。

那么,我該如何配置netbean以使build .jar文件可與derby數據庫一起工作?

(我認為derby是基於文件的,因此構建過程必須生成類似數據庫文件的內容)

如果在執行jar文件的過程中程序崩潰,則可能是異常。 如果它在Netbeans中有效,則該異常可能是由derby.jar的路徑引起的。

我能想到的第一件事是,您已經使用相對路徑在應用程序中包含了derby.jar,並且沒有在項目庫中移動derby.jar。

嘗試執行以下操作:

1:將derby.jar復制到項目文件夾中的目錄(例如/ lib)

2:使用/ lib文件夾中的相對路徑包含jar

編輯:

這是有關在新建數據庫時如何創建數據庫的示例代碼:Class.forName(“ org.apache.derby.jdbc.EmbeddedDriver”);

        Connection con = DriverManager.getConnection("jdbc:derby:C:\\Users\\TheReaver\\MyDB;create=true;user=thereaver;password=12345");
        PreparedStatement st = con.prepareStatement("SELECT ID, NAME FROM APP.TABLE1");
        try
        {
            ResultSet res = st.executeQuery();
        }
        catch(SQLException e) {
            //if table not found, then create all tables
            st.executeQuery("CREATE TABLE TABLE1(ID int, NAME varchar(20)))");
            //execute all statements that create your database
            //or execute an sql file that stores all your queries
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM