问题
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