所以我将MySQL Connector/J 5.1.16添加到我的项目的Build Path中.我正在使用默认的OSX Java包和MAMP Pro 1.9.4与MySQL 5.1.44和Eclipse.
我已经使用以下函数设置了一个简单的Java应用程序:
private static String dbUrl = "jdbc:mysql://127.0.0.1:3306/mpp";
private static String dbUsername = "root";
private static String dbPassword = "root";
private Statement statement = null;
private void dbConnect() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);
statement = connection.createStatement();
} catch(SQLException e) {
System.err.print(e.getMessage() + " ARGH!");
} catch(Exception e) {
System.err.print(e.getMessage() + " FUUUUUUUUUU!");
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到以下错误:
Communications link failure
The last packet sent successfully to the server was 0 …Run Code Online (Sandbox Code Playgroud)