简体   繁体   English

java derby连接到端口1,527上的服务器localhost,消息连接被拒绝

[英]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";

You can learn more here and here 您可以在这里这里了解更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在端口1527上连接到服务器localhost时出错,并显示消息连接被拒绝 - Error connecting to server localhost on port 1527 with message Connection refused Java Web 项目 + JPA/JDBC“连接到端口 1527 上的服务器本地主机时出错,消息连接被拒绝” - Java web project + JPA/JDBC “Error connecting to server localhost on port 1527 with message Connection refused” java derby错误连接到服务器本地主机1527 - java derby Error connecting to server localhost 1527 如何解决:连接到本地主机时出错:Java中的连接被拒绝 - How to fix: Error connecting to localhost: Connection Refused in Java 在Java中连接到FTP端口990时“连接被拒绝” - “Connection refused” when connecting to FTP port 990 in Java 连接到本地主机时出错:8060:java.net.ConnectException:连接被拒绝 - Error connecting to localhost:8060: java.net.ConnectException: Connection refused 在端口1527上连接到服务器localhost时出错,消息已在使用中 - Error connecting to server localhost on port 1527 with message already in use Java RMI客户端和远程服务器连接被拒绝到本地主机 - Java RMI client and remote server Connection Refused to localhost 拒绝连接derby数据库 - Connection to derby database refused 如何通过Java在指定端口上启动Derby Server - How to start Derby server on the specified port by java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM