Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically setting derby.system.home

Tags:

java

derby

javadb

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)?

like image 966
pn1 dude Avatar asked Sep 28 '10 06:09

pn1 dude


People also ask

How do I connect to Derby database in Windows?

connect 'jdbc:derby:c:\temp\db\FAQ\db'; If you want to connect to a Derby database which is running in server mode then you can use the following command. connect 'jdbc:derby://localhost:1527/c:\temp\db\FAQ\db;create=true'; To disconnect from the database.

How do I connect to Derby database in eclipse?

Choose Window > Preferences from the menu to open the Eclipse Preferences dialog. Navigate to Connectivity > Driver Definitions. Select the Derby 10.2 folder and click Add.... In the New Driver Definition dialog, select Derby Client JDBC Driver and click OK.


1 Answers

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);
like image 183
aioobe Avatar answered Oct 02 '22 21:10

aioobe