How can I start apache derby programmatically jar file?

流过昼夜 提交于 2020-01-09 08:11:09

问题


I have a Java application, which uses Apache Derby. Using Eclipse Export option, I exported it as JAR file. When I am running Eclipse, and the server is connected to port 1527, the JAR executes correctly.

However when eclipse is closed, (and the server is not connected to 1527) on executing jar, i get this error

java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.

This is understandable. But i want to distribute the JAR. So is there a way to start the server programmatically, whenever JAR is executed?


回答1:


You can start the NetworkServer programmatically:

NetworkServerControl serverControl = new NetworkServerControl(InetAddress.getByName("myhost"),1621)

serverControl.shutdown();



回答2:


Simplest is to use embedded Derby

        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        conn = DriverManager.getConnection("jdbc:derby:" + DATA_STORE + ";create=true");



回答3:


You need to start the server programmatically.

How this is done is documented in the manual:

http://db.apache.org/derby/docs/10.8/adminguide/tadminconfig814963.html



来源:https://stackoverflow.com/questions/9725376/how-can-i-start-apache-derby-programmatically-jar-file

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