0

How can I access my localhost from my Android device I am using by Fedora 21 and my android device is Nexus 5, someone can explain me step by step the path of connection. By this article [Postgresql not connecting to android using JDBC throwing org.postgresql.util.PSQLException: The connection attempt failed

I change this file: 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  

but this not help me...

it's me java - JDBC source:

 @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;
        }
    }

it's me logcat output:

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.

it shows this is crashing between Row 20 to Connection Successfully at getConnection().

Thanks.

Samet ÖZTOPRAK
  • 3,112
  • 3
  • 32
  • 33
Michael Horojanski
  • 4,543
  • 4
  • 33
  • 34
  • Make sure the address in the pg_hba file is correct .That is most likely the problem.And also ensure that your postgres server is running on the local host port (use something like 'netstat -lnptu' to see which programs are using which ports) – Clyde D'Cruz Apr 23 '15 at 08:27
  • What is your localhost? Every pc is its own localhost. Every Android device is its own localhost. – greenapps Apr 23 '15 at 08:36
  • Please show the url you use in your Android client code. – greenapps Apr 23 '15 at 08:40
  • Well, first, it isn't "localhost" from the perspective of the Android device. Anyway, **show your code** and the **exact error message** please. Also, really, for most cases using PostgreSQL via Android isn't ideal, it's often better to use a web service. – Craig Ringer Apr 23 '15 at 09:04

0 Answers0