no postgresql user name specified in startup packet

╄→尐↘猪︶ㄣ 提交于 2019-12-10 17:41:02

问题


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?

来源:https://stackoverflow.com/questions/18630323/no-postgresql-user-name-specified-in-startup-packet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!