我正在開發一個Android應用程序,並且我正在使用與PostGIS捆綁在一起的PostgreSQL。我想使用本地數據庫,但通過'本地主機'連接不起作用,我試過替代使用'127.0.0.1',而不是它的工作,我得到以下錯誤:無法連接到PostgreSQL數據庫作爲'localhost'
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
使用我的網絡的ipv4地址工程,但我無法通過本地主機連接。我該如何解決這個問題? 我pg_hba.conf的樣子:
...
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 192.168.1.1/24 trust
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host replication postgres 127.0.0.1/32 trust
#host replication postgres ::1/128 trust
和我的postgresql.conf樣子:
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5123 # (change requires restart)
max_connections = 100 # (change requires restart)
我在Eclipse代碼看起來我的服務器類中像
private String DB_URL = "jdbc:postgresql://" + Server.getDbserver() + ":" + Server.getDbport() + "/postgis";
我的變量看起來像。
private static String dbserver = "localhost";
private static int dbport = 5123;
作爲總結,通過我的網絡的IPv4(例如192.168.1.199)的作品連接,而是通過「本地主機」或「127.0.0.1」生成我,我上面貼的錯誤連接。
那麼,PostgreSQL實際上在Android OS *內運行*? – 2014-12-02 09:57:38
我不知道我明白你想說什麼。 – MrSilent 2014-12-02 10:19:02
這是http://dba.stackexchange.com/questions/83851的轉貼。在Android上安裝postgresql **服務器**是個不小的功夫,請參閱[將Postgresql服務器移植到Android](https://groups.google.com/forum/#!topic/pgandroid/STg8xObGFlo)並且它不能在不知道你在做什麼的情況下完成。 – 2014-12-02 10:22:09