首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Java中删除CommunicationException?

如何在Java中删除CommunicationException?
EN

Stack Overflow用户
提问于 2013-12-19 15:31:49
回答 1查看 1.5K关注 0票数 0

我只是想用下面的代码来显示mysql服务器的当前状态。

代码语言:javascript
复制
public static void main(String[] args) throws Exception {

    String dbURL = "jdbc:mysql://Localhost:3306";
    String username ="root";
        String password = "trace";
        Connection dbCon = null;
        Statement stmt = null;
        ResultSet rs = null;
        String query ="SHOW GLOBAL STATUS";
       Class.forName("com.mysql.jdbc.Driver").newInstance();
    dbCon = DriverManager.getConnection(dbURL, username, password);
        stmt = dbCon.prepareStatement(query);
         rs = stmt.executeQuery(query);
         System.out.println(rs);
         while(rs.next())
         {
           String Counter = rs.getString(1);
           int val=rs.getInt(2);
           System.out.print("Counter Name : " + Counter);
           System.out.print("---   Value : " + val);
         }
      }

但是我得到了这个错误:

代码语言:javascript
复制
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

发布于 2013-12-19 15:42:55

您正在创建与mysql的连接,但未提及数据库名称

代码语言:javascript
复制
jdbc:mysql://Localhost:3306 

它应该被定义为

代码语言:javascript
复制
jdbc:mysql://Localhost:3306/test

它可能会解决你的问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20675818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档