connection link failure mysql - java

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:
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. 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

It seems this is a network issue, if the devices are in the same LAN don't use your internet IP. Or even if the devices are in different network your router could be blocking your connection.

Related

Can't connect to remote MySQL server

I'm trying to open a connection from my NetBeans IDE to my remote MySQL database. I've put in what I think is the correct parameters in the response fields but when I try to test the connection it gives me this error message:
Cannot establish a connection to
jdbc:mysql://198.136.54.104:3306/myedigit_FirstDb?zeroDateTimeBehavior=convertToNull
using com.mysql.jdbc.Driver
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.
Please let me know if you need any more information I'll be happy to provide it.
Your host may not allowing remote connection.
You may need to add Access Host by Login into your host server and go to Remote MySql (I am referring GoDaddy)
You need to provide either your IP Address in host or % to access remotely from anywhere.

MySQL connectivity from an external network with java

Hey guys i'm trying to connect mysql database from my friend's wifi. The database connects and works fine from all my other devices with are all on the same network but i want to connect to the database from an external network(my friends network).
I have replaced localhost/device ip with my public ip address which i got from whatsmyip.com
String connectionUrl = "jdbc:mysql://myPublicIp:3306/trial";
and i ran it from my friend's home:
this is what i got:
com.mysql.jdbc.CommunicationException: Communications link failure due to underlying exception:
BEGIN NESTED EXCEPTION
java.net.Connect.Exception
MESSAGE: Connection timed out: connect
As i said there is no prob with the code, it works fine for locally connected devices. I wanted to know if my string's syntax is wrong.
Assuming my public ip address is 50.50.50.50 and my device running mysql is 192.168.x.x and the port is 3306 how should i format my string.
Thanks.
You should forward your 3306 port for the device which got the database on it, otherwise your router can't decide which device to look for when you request connection through this port and it won't let anything through instead.

Connecting to Server from mobile when public IP for both is same

I am working on a client server application where my Server is my PC.I have done port forwarding to connect to the server.I was able to connect to the server using GPRS module, but my client application needs to be run on my Android phone.I created a simple app to connect to the server from android phone.I was able to connect to Server when i tried using cellular network but when my phone was connected to Wifi i was getting
connect Refused :ECONNREFUSED
when i researched somewhat i find out that the public ip of both mobile and Server are same. Is this the reason that i am not able to connect to server from my phone while connected to WiFi.
Yes the reason is that they have same Public IP i.e they are on same Network. Instead give the local IP of the Pc it will connect to the server.

How to connect Android device to a Java program via sockets?

I need to connect an android device to my java program via socket connection. The device is working as server. The problem is that while trying out socket connection I need to give IP address and port number of server.
Is there something like a static IP address for an Android device to connect? If not, is there any alternative way to establish a socket connection between the device and my program?
As the device has to have a connection to the same network as the computer, it has to have an IP address configured. So you have to use that one.
The used port is defined by the server application running on your device.
If you have the problem that anyhow a normal network connection is not possible, but you have an ADB connection, you can forward local pots to the device and let your server listen:
http://developer.android.com/tools/help/adb.html#forwardports
Over a mobile connection (GPRS, EDGE, UMTS, HSDPA) there will be no practicable way to establish a connection from somewhere to your device (instead you have to do it the other way, while canceling the whole client-server directive), in cause of the used IP sharing. In that case you have a problem of which I'm not aware if it's possible in general, not to mention how you could achieve this.
Otherwise you simply have to configure a static IP for your device when connected to your local network, or you have to evaluate the actual IP of your device every most of the time, while using it with this configuration:
Resolve it by the device itself
Resolve InetAdress from DhcpInfo
Documentation for DhcpInfo
Resolve by using ADB command

Advantage Database Local server with JDBC

Hi I am trying to connect through JDBC on an Advantage local server.
I have tested many connections strings, like for example:
connection = DriverManager.getConnection(
"jdbc:extendedsystems:advantage://localhost:6262;catalog=C:\\bdl\\database\\BDL.add;TableType=cdx;LockType=proprietary", "adssys", "no");
I am searching for over three days now. I am getting always the error message connection refused. I only want to connect and access the files , and not on any advanced database server. I have now idea any more.
The ADS JDBC driver doesn't support ALS (Advantage Local Server), you have to install an actual ADS server.
http://devzone.advantagedatabase.com/dz/webhelp/Advantage10.1/devguide_ads_and_java_1.htm
If you have a running ADS server make sure there is no firewall that blocks traffic on port 6262 (or whatever port you're using).

Categories

Resources