简体   繁体   English

从jar访问derby数据库

[英]Accessing derby database from jar

I have created database in derby and store it in /data folder in the root of my project folder. 我已经在derby中创建了数据库,并将其存储在项目文件夹根目录的/ data文件夹中。 in the application i am using embedded drivers. 在应用程序中,我正在使用嵌入式驱动程序。 when i run my application from netbeans i am getting no errors. 当我从netbeans运行我的应用程序时,我没有任何错误。 when i build the application and run the jar i am getting database not found error . 当我构建应用程序并运行jar时,出现数据库未找到错误 Here is the code that i am using to connect to the database. 这是我用来连接数据库的代码。

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

            Properties p = new Properties();
            p.put("user", "usman");
            p.put("password", "******");
            DriverManager.getConnection("jdbc:derby:data/SalePurchase", p);

Can anyone tell me how can i access the database folder "SalePurchase" when i run it in the jar . 谁能告诉我在jar中运行数据库文件夹“ SalePurchase”时该如何访问。 .

data/SalePurchase is a relative path. data / SalePurchase是相对路径。 The question is what is it relative to. 问题是它相对于什么。 The manual () states that 手册 ()指出

You define the system directory when Derby starts up by specifying a Java system property called derby.system.home.If you do not specify the system directory when starting up Derby, the current directory becomes the system directory. 在Derby启动时,您可以通过指定Java系统属性derby.system.home来定义系统目录。如果在启动Derby时未指定系统目录,则当前目录将成为系统目录。

Derby uses the derby.system.home property to determine which directory is its system directory - and thus what databases are in its system, where to create new databases, and what configuration parameters to use. Derby使用derby.system.home属性确定哪个目录是其系统目录-从而确定其系统中有哪些数据库,在哪里创建新数据库以及要使用哪些配置参数。 See the Derby Reference Manual for more information on this property. 有关此属性的更多信息,请参见《 Derby参考手册》。

If you specify a system directory at startup that does not exist, Derby creates this new directory - and thus a new system with no databases-automatically. 如果在启动时指定了不存在的系统目录,则Derby会自动创建此新目录-从而创建一个没有数据库的新系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM