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


Android Emulator でプログラムを実行します。私のプログラムには次のエラーがあります。

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

プログラムのどこが間違っていますか? どうすればよいですか?

4

0 に答える 0