[英]java derby connecting to server localhost on port 1,527 with message Connection refused
I am trying to connect derby client database to my java project. 我正在尝试将derby客户端数据库连接到我的java项目。 At first everything was fine.After 3 days later Suddenly the derby db could not be connected.It's showing this message "Error connecting to server localhost on port 1,527 with message Connection refused:"
起初一切都很好.3天后突然,德比数据库无法连接。它显示此消息“错误连接到端口1,527上的服务器localhost,消息连接被拒绝:”
Database connection code: 数据库连接代码:
public Connection getConnection() {
try {
String driver = "org.apache.derby.jdbc.ClientDriver";
try {
Class.forName(driver);
} catch (java.lang.ClassNotFoundException e) {
e.printStackTrace();
}
String dbURL2 = "jdbc:derby://localhost:1527/D:/Java Project/Alo Art Academy/AloArtDB;create=true";
String user = "HabibDB";
String password = "habib2017";
Connection conn = DriverManager.getConnection(dbURL2, user, password);
if (conn != null) {
System.out.println("Connected to database #2");
}
return conn;
} catch (SQLException ex) {
ex.printStackTrace();
return null;
}
}
Then edited C:\\Program Files\\Java\\jre1.8.0_77\\lib\\security the java.policy file and add the following permission 然后编辑C:\\ Program Files \\ Java \\ jre1.8.0_77 \\ lib \\ security java.policy文件并添加以下权限
permission java.net.SocketPermission "localhost:1527", "listen";
but no luck! 但没有运气! :(
:(
stacktrace: 堆栈跟踪:
java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1,527 with message Connection refused: connect.
at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at alo.art.academy.workstation.getConnection(workstation.java:46)
at alo.art.academy.workstation.<init>(workstation.java:27)
at alo.art.academy.AloArtAcademy$1.run(AloArtAcademy.java:26)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
What is wrong with me? 我是怎么了?
I think you have a problem in your URL why you specify the exact path of your Database : 我认为您的URL中存在问题,为什么要指定数据库的确切路径:
String dbURL2 = "jdbc:derby://localhost:1527/D:/Java Project/Alo Art Academy/AloArtDB;create=true";
The connection URL syntax is as follows: 连接URL语法如下:
jdbc:derby:[subsubprotocol:][databaseName][;attribute=value]*
So change your URL like this : 所以改变你的URL如下:
String dbURL2 = "jdbc:derby://localhost:1527/AloArtDB;create=true";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.