繁体   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