Hello,everyone.
Recently,I have been playing around with Java and JDBC using MySQL database,which is my favourite.However,after I put the mysql-connector...jar to my JDK installation location /usr/local/jdk1.6/jre/lib/ext/.jar and I used the sample script on the Internet and try to connect to,it returned a failure message.
Exception: Communications link failure in the command prompt
Please drop me a line if you have any ideas with this error.Thanks a million.
The sample script goes like:
Code:
import java.sql.*;
public class MySqlConnectionUrl {
public static void main(String [] args) {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver") ;
System.out.println("MySQL JDBC driver loaded ok.");
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mysql?"
+ "user=user&password=mypasswd");
System.out.println("Connected with host:port/database.");
con.close();
}
catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
}
}
}