0

我如何从我使用 Fedora 21 的 Android 设备访问我的本地主机,而我的 Android 设备是 Nexus 5,有人可以逐步向我解释连接路径。通过这篇文章 [Postgresql not connected to android using JDBC throwing org.postgresql.util.PSQLException: The connection attempt failed

我更改了这个文件:pg_hba.conf

 # IPv4 local connections:
    host    all             all             10.0.2.2                trust

postgresql.conf:

listen_addresses = '*'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 5432                             # (change requires restart)
max_connections = 100  

但这对我没有帮助...

是我 java - JDBC 源代码:

 @Override
        protected Void doInBackground(Void... arg0){

            try
            {
                Log.d("Start connection","Start connection");
                String URL = "jdbc:postgresql://" + "10.0.2.2" + ":" + "5432/keen";
                String USER = "keen";
                String PASS = "q1w2e3";
                Log.d("Row 10","Row 10");

                Class.forName("org.postgresql.Driver").newInstance();
                Log.d("Row 20","Row 20");

                Connection conn = DriverManager.getConnection(URL, USER, PASS);
                Log.d("Connection Successfully","Connection Successfully");

                Statement stmt = conn.createStatement();

                String SQL = "CREATE TABLE test (id bigserial primary key);";

                stmt.executeUpdate(SQL);

                conn.close();
            }
            catch (ClassNotFoundException e)
            {
                Log.d("Connection fail","Connection fail");

            }
            catch (SQLException e)
            {

                Log.d("Connection fail","Connection fail");

            }
            catch (Exception e)
            {
                Log.d("Connection fail","Connection fail");

            }
            return null;
        }
    }

这是我的 logcat 输出:

04-23 15:52:23.645  15749-15749/com.gorbin.androidsocialnetworksextended.keen I/Google Maps Android API﹕ Google Play services package version: 7329438
04-23 15:52:23.843  15749-15927/com.gorbin.androidsocialnetworksextended.keen D/Start connection﹕ Start connection
04-23 15:52:23.844  15749-15927/com.gorbin.androidsocialnetworksextended.keen D/Row 10﹕ Row 10
04-23 15:52:23.847  15749-15927/com.gorbin.androidsocialnetworksextended.keen D/Row 20﹕ Row 20
04-23 15:53:19.118  15749-15767/com.gorbin.androidsocialnetworksextended.keen W/System.err﹕ org.postgresql.util.PSQLException: Connection to 10.0.3.2:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
04-23 15:53:19.134  15749-15767/com.gorbin.androidsocialnetworksextended.keen I/art﹕ System.exit called, status: 0
04-23 15:53:19.134  15749-15767/com.gorbin.androidsocialnetworksextended.keen I/AndroidRuntime﹕ VM exiting with result code 0, cleanup skipped.

它表明这是在第 20 行到 getConnection() 成功连接之间崩溃。

谢谢。

4

0 回答 0