0

I'm just trying to display the current status of mysql server by using the following code.

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);
         }
      }

But I get this error:

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.

How can i solve this?

STT LCU
  • 4,348
  • 4
  • 29
  • 47
user3099091
  • 21
  • 1
  • 5

1 Answers1

0

You are creating connection with your mysql and didn't mentioned database name

jdbc:mysql://Localhost:3306 

it should be defined as

jdbc:mysql://Localhost:3306/test

it might solve your problem

Noman ali abbasi
  • 539
  • 2
  • 13