0

One question, what IP/Host address should i use to connect to my PG database on my Android app? I have a postgresql database running on my machine. Im using eclipse by deploying my app on my cellphone instead of using the avd emulator. I can use '10.0.2.2' (localhost) when im testing it in the emulator and it works perfectly. However, if i try to access through my phone, the pg connection times out. I've tried putting my pc ip address as the host address on the postgresql connection url, but its not working.

Anyone knows what IP address should i use? I figured it'd be my machine ip address, but thats not it :/ .

Oscar Valdez Esquea
  • 890
  • 1
  • 11
  • 26
  • 1
    You should not directly open a database connection from a phone device. Instead, use a (REST) Web Service layer to communicate with your database. You can write this web service layer in a different language than Java. – Luiggi Mendoza Oct 09 '14 at 17:34
  • Thanks for your comment Luiggi. Can you link me to some example on how to implement it? – Oscar Valdez Esquea Oct 09 '14 at 17:37
  • There are plenty examples about this on the net. I can only provide the keywords to search for a tutorial: *`` rest services tutorial*. For example: *java rest services tutorial*, *c# rest services tutorial*, and on. – Luiggi Mendoza Oct 09 '14 at 17:39
  • One more question Luigi, what's the issues in opening a db connection from a phone device? Even when the connection will only be open for a mere seconds to get the socket IP Address/Port, would there be any major issues? – Oscar Valdez Esquea Oct 09 '14 at 17:59
  • See http://stackoverflow.com/q/15853367/398670 and http://stackoverflow.com/questions/tagged/android+postgresql+jdbc . Bad idea. Avoid long-connection-oriented processes on mobile devices that might have bad connectivity. – Craig Ringer Oct 10 '14 at 01:49

0 Answers0