Postgresql not connecting to android using JDBC throwing org.postgresql.util.PSQLException: The connection attempt failed

前端 未结 1 1982
野趣味
野趣味 2020-12-21 11:07

I am developing an android application for which I need to connect to Postgresql database, I installed it 9.3 version, and checked in PGAdminIII it is connecting. I also cre

1条回答
  •  醉梦人生
    2020-12-21 11:27

    Your problem is that 127.0.0.1 on the Android goes to the virtual Android device and not to your machine hosting the PostgreSQL database. Referencing the Android emulator documentation for networking:

    Each instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine's network interfaces and settings and from the internet. An emulated device can not see your development machine or other emulator instances on the network. Instead, it sees only that it is connected through Ethernet to a router/firewall.

    And below that, there is a table for the virtual router:

    Android virtual router network

    And further down in a section about using 127.0.0.1 (emphasis mine):

    Also note that the address 127.0.0.1 on your development machine corresponds to the emulator's own loopback interface. If you want to access services running on your development machine's loopback interface (a.k.a. 127.0.0.1 on your machine), you should use the special address 10.0.2.2 instead.

    You should use 10.0.2.2 rather than 127.0.0.1 if you want to connect to the development machine.

    0 讨论(0)
提交回复
热议问题