How can I run the apache derby program jar file?
I have a Java application that uses Apache Derby. Using the Eclipse Export option, I exported it as a JAR file. When I start Eclipse and the server is connected to port 1527, the JAR runs correctly.
However, when closing eclipse (and the server is not connected to 1527) while executing the jar, I get this error
java.sql.SQLNonTransientConnectionException: java.net.ConnectException: Error connecting to localhost server on port 1527 with message Connection refused.
This is clear. But I want to distribute the JAR. So, is there a way to start the server programmatically when the JAR is running?
You can start NetworkServer programmatically :
NetworkServerControl serverControl = new NetworkServerControl(InetAddress.getByName("myhost"),1621)
serverControl.shutdown();
The simplest is to use embedded Derby
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
conn = DriverManager.getConnection("jdbc:derby:" + DATA_STORE + ";create=true");
You need to start the server programmatically.
How this is done is described in the manual:
http://db.apache.org/derby/docs/10.8/adminguide/tadminconfig814963.html