简体   繁体   English

mysql连接链接失败

[英]connection link failure mysql

I am trying to connect to my android device with my mysql database, I can do it in local (from a emulation device) but when I use my IP to connect to with my mobile I get: 我正在尝试使用mysql数据库连接到我的android设备,我可以在本地(通过仿真设备)连接它,但是当我使用IP连接到我的手机时,我得到了:

Communication Link failure
The last packet send succesfully to the server was 0 millisecond ago. The driver has not recived any packet from the server

my code is: 我的代码是:

Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://MYIP:3306/BD", "USER", "USER");

with localhost it works: 与本地主机一起工作:

Connection conn=DriverManager.getConnection("jdbc:mysql://10.0.2.2:3306/BD", "USER", "USER");

Thanks for your help. 谢谢你的帮助。

To connect your Android device to Mysql you should use webs ervices . 要将Android设备连接到Mysql,您应该使用web服务 you can find more information in this tutorial 您可以在本教程中找到更多信息

the Tutorial use PHP to creat web services, however you can use any other server side language to connect with mysql database, this will return JSON data that you can parse it to in your android app 教程使用PHP创建网络服务,但是您可以使用任何其他服务器端语言来连接mysql数据库,这将返回JSON数据,您可以将其解析到android应用中

It seems this is a network issue, if the devices are in the same LAN don't use your internet IP. 如果设备位于同一局域网中,请不要使用您的Internet IP,这似乎是网络问题。 Or even if the devices are in different network your router could be blocking your connection. 或者,即使设备位于不同的网络中,您的路由器也可能会阻止您的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM