我正在尝试通过网络客户端连接打开一个只读的Derby数据库(使用ij / derbyclient.jar)。
我创建了一个只读数据库:
jar cMf sample.jar sample
启动Derby Network Server。
我尝试了以下连接网址:
connect 'jdbc:derby:jar://localhost:1527/sample.jar';
connect 'jdbc:derby:jar://localhost:1527/(sample.jar)sample';
connect 'jdbc:derby://localhost:1527/jar:(sample.jar)sample';
但上述网址都不起作用。
唯一有效的网址是:
connect 'jdbc:derby:jar:(sample.jar)sample';
只读Derby数据库似乎只能在嵌入模式下打开。这是真的吗?
解决:
检查“derby.log”后,问题是只读数据库需要能够创建临时文件。
的derby.log:
java.sql.SQLException: Failed to start database 'jar:(sample.jar)sample' with class loader sun.misc.Launcher$AppClassLoader@1d450337, see the next exception for details.
...
Caused by: java.sql.SQLException: Failed to start database 'jar:(sample.jar)sample' with class loader sun.misc.Launcher$AppClassLoader@1d450337, see the next exception for details.
...
Caused by: java.sql.SQLException: Java exception: 'Unable to create temporary file: java.lang.SecurityException'.
...
Caused by: java.lang.SecurityException: Unable to create temporary file
解决方案是为数据库定义临时目录。这可以通过“derby.storage.tempDirectory”属性来完成:
“derby.properties”中的系统范围:
derby.storage.tempDirectory=c:/temp
数据库范围
CallableStatement cs = conn.prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)"); cs.setString(1, "derby.storage.tempDirectory"); cs.setString(2, "c:/temp"); cs.execute(); cs.close();
网络网址为:
connect 'jdbc:derby://localhost:1527/jar:(sample.jar)sample';