5
public class HelloPostgreSQLActivity extends Activity {
    TextView resultArea;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        resultArea = new TextView(this);
        resultArea.setText("Please wait.");
        setContentView(resultArea);
        new FetchSQL().execute();

    }
    private class FetchSQL extends AsyncTask <Void,Void,String> {


        @Override

        protected String doInBackground(Void... params) {
            //TextView tv=(TextView)findViewById(R.id.text);
            String retval = "";
           // String msg="connected";
            try {
                Class.forName("org.postgresql.Driver");
               // tv.setText(msg);  

            }  
             catch (ClassNotFoundException e) {
                e.printStackTrace();
                retval = e.toString();
            }
            String url = "jdbc:postgresql://192.168.1.92/postgres? user = postgres & password = admin";
            Connection conn;
            try {
                DriverManager.setLoginTimeout(25);
                conn = DriverManager.getConnection(url);
                Statement st = conn.createStatement();
                String sql;
                sql = "SELECT 1";
                ResultSet rs = st.executeQuery(sql);
                while(rs.next()) {
                    retval = rs.getString(1);
                }
                rs.close();
                st.close();
                conn.close();
            }
            catch (SQLException e) {
                e.printStackTrace();
                retval = e.toString();
            }
            return retval;
        }
        @Override
        protected void onPostExecute(String value) {
            resultArea.setText(value);
        }
    }
}


I run my program in Android Emulator. My program has the following error.

org.postgresql.util.PSQLException : FATAL: no PostgreSQL Username specified in startup packet.

What's wrong in my program what should i do?

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
Yashwanth
  • 880
  • 3
  • 13
  • 21
  • What happens when you try `DriverManager.getConnection(url, "postgres", "admin");` (and remove the user/password parameters from the URL). –  Sep 05 '13 at 07:41
  • FATAL: no pg_hba.conf entry for host "192.168.1.92", user "postgres",database"postgres",SSL off – Yashwanth Sep 05 '13 at 07:54
  • http://stackoverflow.com/search?q=postgres+no+pg_hba.conf+entry+for+host –  Sep 05 '13 at 07:55
  • It was working well but when I run the program today. It say "Unfortunately program has stopped working". What went wrong? – Yashwanth Sep 06 '13 at 06:06
  • But only one value is returned while i try " select * from student" What should I do to get full row details? – Yashwanth Sep 06 '13 at 13:26

0 Answers0