Java 将用户插入数据库ANDROID应用程序
我正在尝试将用户登录名和密码插入mysql数据库 到目前为止,我得到的是:Java 将用户插入数据库ANDROID应用程序,java,android,Java,Android,我正在尝试将用户登录名和密码插入mysql数据库 到目前为止,我得到的是: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_signup); } public void validateUser(View v) { final EditText userna
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
}
public void validateUser(View v) {
final EditText username = (EditText) findViewById(R.id.username);
final EditText password = (EditText) findViewById(R.id.password);
final String login_name = username.getText().toString();
final String password_name = password.getText().toString();
new Thread(new Runnable() {
public void run() {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://website-name/insert.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", login_name));
nameValuePairs.add(new BasicNameValuePair("password", password_name));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
}
catch (ClientProtocolException e) {
} catch (IOException e) {
}
}
}).start();
Intent homepageIntent = new Intent(signup.this, homepage.class);
startActivity(homepageIntent);
}
}
在我的xml文件中,单击按钮时执行validateUser。但当我运行emulator并创建用户帐户时,我的程序会将我引导到主页,但不会将用户添加到数据库中。我到底做错了什么?试着回应一下http://website-name/insert.php 试着从那里解决问题。。。或者尝试将发送的内容写入文件。若您可以在服务器端回显发送的内容或写入文件,那个么问题就出现了
但不要从客户端登录数据库 catch ClientProtocolException e{}catch IOException e{}不,不,不。永远不要吃异常,尤其是在执行IO时。逐步使用调试器。发生了什么?好吧,我在catch es中放了一些Log.d,所以我不吃任何异常。当我运行程序时,我实际上没有得到任何错误。我的logcat没有错误Slogcat用于记录,而不是调试。逐步使用调试器。看看会发生什么。请不要告诉我你正在通过网络发送未加密的密码…@Simon:谢谢你的提示。我仔细阅读了调试,在过去的几个小时里一直在尝试调试程序。我认为问题在于**HttpResponse response=httpclient.executehttpoppost;**返回空值,因此不会从应用程序屏幕中传入用户名和密码的值。我的php脚本中确实有回显代码,可以回显成功或失败。但它根本没有被执行,这让我觉得我是把HTTP请求弄错了。@getgoodatprogramming从'HttpEntity=response.getEntity;'中得到了什么?我得到了我的系统﹕ 内容类型:text/html,但当我运行response.getContent时;我得到-1