2011-02-28 115 views
1

我在eclipse中創建了客戶端 - 服務器gui日曆應用程序,但它不起作用。我有這樣一個奇怪的例外..有人可以幫我解決它。作爲一個服務器,我使用mysql和fat jar插件來做eclipse來製作可運行jar文件。java jdbc嵌套異常

com.mysql.jdbc.CommunicationsException: Communications link failure dueto underlying exception: 

BEGIN嵌套異常

java.net.ConnectException 
MESSAGE: Connection refused 

堆棧跟蹤:

java.net.ConnectException: Connection refused 
at java.net.PlainSocketImpl.socketConnect(Native Method) 
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) 
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213) 
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200) 
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) 
at java.net.Socket.connect(Socket.java:529) 
at java.net.Socket.connect(Socket.java:478) 
at java.net.Socket.<init>(Socket.java:375) 
at java.net.Socket.<init>(Socket.java:218) 
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256) 
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271) 
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771) 
at com.mysql.jdbc.Connection.<init>(Connection.java:1555) 
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) 
at java.sql.DriverManager.getConnection(DriverManager.java:582) 
at java.sql.DriverManager.getConnection(DriverManager.java:185) 
at calendarapplication.gui.CalendarApplication.main(CalendarApplication.java:40) 

END嵌套異常

發送到服務器的最後一個數據包是2 ms前。

at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847) 
at com.mysql.jdbc.Connection.<init>(Connection.java:1555) 
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) 
at java.sql.DriverManager.getConnection(DriverManager.java:582) 
at java.sql.DriverManager.getConnection(DriverManager.java:185) 
at calendarapplication.gui.CalendarApplication.main(CalendarApplication.java:40) 

Exception in thread "main" java.lang.NullPointerException 
at calendarapplication.gui.CalendarApplication.main(CalendarApplication.java:63) 

問候,

+1

驗證它是如何工作的?我的意思是,你試圖連接到哪個服務器/端口?從堆棧跟蹤看來,你似乎試圖連接到一個服務器,你有沒有訪問或沒有運行MySQL。 – chahuistle 2011-02-28 21:13:17

回答

0

看起來像你的服務器(MySQL的)是不是在指定的地址和端口啓動。

2

檢查您的JDBC連接字符串以確保您有正確的端口號。默認情況下,MySQL在3306上運行。您可以使用> netstat -b命令