我想从 java 打开一个 MySql 连接。这是我的代码:
public static void main(String [] args){
String line;
Connection connection;
Statement statement;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "manager");
statement =connection.createStatement();
System.out.println("Database Created...!!!");
System.out.println("Connected");
}
但它给了我这个错误:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 1 ms ago.
...
Caused by: java.net.ConnectException: Connection timed out: connect
为什么?它应该怎么做?请帮我。谢谢你...