如何从Android连接到MySQL数据库?

时间:2012-08-03 15:32:32

标签: android mysql

我尝试通过mysql-connector-java-5.1.21-bin.jar库连接MySQL。 这是我的代码:

class Test {
    private static final String CONNECTION = "jdbc:mysql://x.x.x.x:3306/db";

    private void getMySQL() {
    Connection con = null;
    String str_res = "";

    try{
    Class.forName("com.mysql.jdbc.Driver").newInstance();
        // Properties for user and password. 
        Properties p = new Properties();
    p.put("user","***");
    p.put("password","***");

        // Now try to connect
    Connection c = DriverManager.getConnection(CONNECTION, p);
        ...
    } catch (Exception e) {}    
}

但我有一个网络例外:

com.mysql.jdbc.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.
java.net.SocketException: The operation timed out
null
null
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
0

怎么了?

0 个答案:

没有答案