7

Need to move the database and log files of JavaDB (derby) db files into deployment directories. The database is working in the application startup directory as JavaDB creates a folder with the name of the database (in my case mydb), but I want to move that dir into a subdir called data/ creating data/mydb. I can do this with the connect call:

DriverManager.getConnection("jdbc:derby:data/mydb;create=false");

and this works. But I'd like to programmatically explicitly set the value of

derby.system.home=data/
derby.stream.error.file=log/derby.log

So I can do:

DriverManager.getConnection("jdbc:derby:mydb;create=false");

and all dbs would be in that data/ dir. And the derby log file would be in logs/! I just can't seem to figure this out. Anyone help? Is there a way to set those properties programatically (because it's embedded)?

Raedwald
  • 46,613
  • 43
  • 151
  • 237
pn1 dude
  • 4,286
  • 5
  • 30
  • 26

1 Answers1

7

The documentation (Derby developers guide: Setting Derby properties) suggests something like:

Properties p = System.getProperties();
p.setProperty("derby.system.home", "C:\databases\sample");

I've also seen

/* setting an attribute in a Properties object */
Properties myProps = new Properties();
myProps.put("create", "true");
Connection conn = DriverManager.getConnection("jdbc:derby:sampleDB", myProps);
aioobe
  • 413,195
  • 112
  • 811
  • 826
  • This works for database properties and I actually use something close to this in my code. But this does not work for System-Wide properties. – pn1 dude Sep 28 '10 at 07:03
  • The link in the answer contains the above code under section *Setting Derby properties* -> *Changing System-wide properties programmatically*. So the error is perhaps elsewhere in your code. (You could also try the other approach, "Changing the system-wide properties by using the derby.properties file". – aioobe Sep 28 '10 at 07:08
  • 1
    Nope you're correct! The first part got me going down the correct path. Duh its a darn system property. So I added: System.setProperty("derby.system.home", "./data/"); and System.setProperty("derby.stream.error.file", "../log/derby.log"); (<- this was because the root dir is now data/) and it all works great! Yeah I don't want to use a derby.properties file. – pn1 dude Sep 28 '10 at 07:09
  • @aioobe link is broken – Njax3SmmM2x2a0Zf7Hpd Apr 25 '14 at 08:31