我已经在eclipse中创建了客户机-服务器gui日历应用程序,但它不起作用。我有个奇怪的例外。。有人能帮我解决吗。作为一个服务器,我为eclipse使用mysql和fat jar插件来生成可运行的jar文件。
com.mysql.jdbc.CommunicationsException: Communications link failure dueto underlying exception:
开始嵌套异常
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)
结束嵌套异常
最后一个发送到服务器的数据包是在2毫秒前。
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)
当做,
最佳答案
检查JDBC连接字符串以确保端口号正确。默认情况下,MySQL在3306上运行。您可以使用>netstat-b命令来验证它