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

I am using Netbeans.
If I go to the Services Tab and rightclick Java DB and start Server it works fine.

How can I do this programmaticly at Runtime. I just need whatever method will start the Java DB Server.

oers
  • 18,436
  • 13
  • 66
  • 75
Dave_P
  • 174
  • 2
  • 16

2 Answers2

2

Have a look at how to use JavaDB with a desktop application. They describe how to start it programmatically there.

tobiasbayer
  • 10,269
  • 4
  • 46
  • 64
  • Actually there is not one answer on that page on how to start the db servers, only how to connect to them once they are created and started. – Dave_P Dec 15 '11 at 18:22
  • The embedded server will be started automatically as soon as you load the driver with `Class.forName("org.apache.derby.jdbc.EmbeddedDriver");` as described on the page. – tobiasbayer Dec 15 '11 at 20:35
1

You need to start the NetworkServerControl additional documentation can be found here

NetworkServerControl server = new NetworkServerControl(InetAddress.getByName("localhost"), port);
oers
  • 18,436
  • 13
  • 66
  • 75
  • This looks like it should be the one I needed but had a little trouble implementing it. Do you know where there may be some samples I can see to view how it is done? – Dave_P Dec 15 '11 at 18:20
  • Search on "embedded server"; that's the terminology that Derby use for this, I believe. For example: http://db.apache.org/derby/docs/10.8/adminguide/radminembeddedserverex.html – Bryan Pendleton Dec 15 '11 at 19:27
  • Embedded and Network Server are not the same, the network server can be accessed from anywhere the embedded database is only available in the current runtime. And I provided an additional link. – oers Dec 16 '11 at 07:35