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.
我的计划有什么问题我该怎么办?