我只是想用下面的代码来显示mysql服务器的当前状态。
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);
}
}但是我得到了这个错误:
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.我该如何解决这个问题呢?
发布于 2013-12-19 15:42:55
您正在创建与mysql的连接,但未提及数据库名称
jdbc:mysql://Localhost:3306 它应该被定义为
jdbc:mysql://Localhost:3306/test它可能会解决你的问题
https://stackoverflow.com/questions/20675818
复制相似问题