title: java derby connecting to server localhost on port 1,527 with message Connection refused
body: <p>I am trying to connect derby client database to my java project. 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:"</p>
  
  <p>Database connection code:</p>
  
  <pre><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;
      }
  }
  </code></pre>
  
  <p>Then  edited C:\Program Files\Java\jre1.8.0_77\lib\security
   the java.policy file and add the following permission</p>
  
  <pre><code>    permission java.net.SocketPermission "localhost:1527", "listen";
  </code></pre>
  
  <p>but no luck! :(</p>
  
  <p>stacktrace:</p>
  
  <pre><code>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.&lt;init&gt;(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)
  </code></pre>
  
  <p>What is wrong with me?</p>