Programmatically setting derby.system.home

不打扰是莪最后的温柔 提交于 2019-12-20 14:21:05

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/3810198/programmatically-setting-derby-system-home

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!