将在线mysql数据库连接到Java应用程序

时间:2015-07-03 03:08:40

标签: java mysql

如何将在线mysql数据库连接到java应用程序?我使用下面的代码来获取与我的数据库的连接。

private static Connection con;
        public static Connection connect() throws Exception {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        String url = "jdbc:mysql://host/database";
        con = DriverManager.getConnection(url, "username", "password");
        return con;
    }

但每次都会给我以下错误。

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.

我该怎么办?

0 个答案:

没有答案
相关问题