简体   繁体   中英

Accessing derby database from jar

I have created database in derby and store it in /data folder in the root of my project folder. in the application i am using embedded drivers. when i run my application from netbeans i am getting no errors. when i build the application and run the jar i am getting database not found error . 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 . .

data/SalePurchase is a relative path. 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 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. See the Derby Reference Manual for more information on this property.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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