2014-09-19 43 views
2

我繼承了一些使用derby數據庫的源代碼,但啓動服務器不再工作。Java derby數據庫服務器將不再啓動

public void startDatabase(){ 
    try { 
     Class.forName("org.apache.derby.jdbc.ClientDriver"); 
     System.setProperty("derby.system.home", "D:\\runtime-my.product\\log"); 

     NetworkServerControl nsc = new NetworkServerControl(InetAddress.getByName("localhost"), 1527) 
     nsc.start(null); 
     nsc.ping(); 
    catch (Exception e){ 
     e.printStackTrace(); 
    } 
} 

nsc.ping()被exectued,以下異常被拋出:

Exception: java.lang.Exception: DRDA_NoIO.S:Could not connect to Derby Network Server on host 127.0.0.1, port 1527: Connection refused: connect 

有什麼明顯的遺漏或錯碼的那些行?

回答

2

檢查服務器是否啓動。您需要明確啓動服務器。或者通過 設置系統屬性derby.drda.startNetworkServer=true

2

在套接字準備連接之前,NetworkServerControl構造函數返回需要一段時間。在我的機器上約50毫秒。我改變你的榜樣,像這樣:

NetworkServerControl nsc = new NetworkServerControl(InetAddress.getByName("localhost"), 1527); 
    nsc.start(null); 
    for (int i = 0; i < 10; ++i) { 
     try { 
      System.out.println("Attempting to ping..."); 
      nsc.ping(); 
      break; 
     } catch (Exception e) { 
      System.out.println(e.getMessage()); 
     } 
     Thread.sleep(10); 
    } 

它成功的嘗試5 ...

+0

感謝您分享這條信息! – Markus 2014-09-25 11:54:11