qq_37761523
qq_37761523
2017-05-30 13:59

android利用JDBC连接服务器mysql失败

  • android
  • 服务器
  • mysql
  • jdbc

加载的mysql驱动是mysql-connector-java-5.1.30-bin.jar
服务器是腾讯云服务器
代码:

 try
                {
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                    con = (Connection) DriverManager.getConnection(
                            "jdbc:mysql://118.89.232.64:3306/info_file","name","password");
                    Log.i("mysqltest","Success connect Mysql server!");
                }catch( SQLException ee)
                {
                    Log.i("mysqltest","Error loading Mysql Driver!ee");
                    ee.printStackTrace();
                }
                catch (Exception e)
                {
                    Log.i("mysqltest","Error loading Mysql Driver!e");
                    e.printStackTrace();
                }

程序能打开,但是不能与数据库建立连接,log信息:
05-30 20:04:35.614 8362-8362/? W/System.err: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
05-30 20:04:35.614 8362-8362/? W/System.err: The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
而且就算乱改url或者断网出现的都是同样的信息,求帮助

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答