i want to open a MySql connection from java. and this my code :
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");
}
but it give me this error:
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
why? and what it should be do? please help me. thank you...