Java DB - Starting Server within application

跟風遠走 提交于 2019-12-11 17:02:12

问题


I am aware that there are tons of questions around about this problem but I tried every ungodly way to fix it, still no result.

I have created a "test" Derby database within Netbeans. Everything works fine, I can execute SQL commands, alter tables and all within application. But i have to start the server everytime when I open netbeans. But I want my application's itself to start the server with codes. I guess i tried everything to do it.

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

server = new NetworkServerControl(InetAddress.getLocalHost(),1527);
server.start(null);

conn = DriverManager.getConnection("jdbc:derby://localhost:1527/test;create=true;");

This is what i get if i dont start the server manually.

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

I tried different drivers, i tried putting jar and sdk files to my app file. I added permission to socket 1527 to java.security file.

No matter what i do, i must start the server manually or i get this chunk of code.

来源:https://stackoverflow.com/questions/25832279/java-db-starting-server-within-application

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