我在应用程序中创建了一个SQLite数据库。当用户注册该时间时,我希望系统检查用户和电子邮件ID是否已经存在于数据库内部,然后只创建新行,用户之前没有注册。如何实施检查部分?任何意见将不胜感激。先感谢您!
答案 0 :(得分:2)
mLogin.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mCursor = db.execSQL("SELECT * FROM Friend where F_email='"+mUserId.getText().toString()+"' and Pass='"+mPassword.getText().toString()+"'");
if(mCursor.getCount() > 0)
{
email_id = mUserId.getText().toString();
Intent i1 = new Intent(getApplicationContext(),
BuddyInOut.class);
startActivity(i1);
mUserId.setText("");
mPassword.setText("");
}
else {
// AlertDialog on invalid User Name and Password
AlertDialog.Builder mAlert = new AlertDialog.Builder(
Login.this);
mAlert.setTitle("Login");
mAlert.setMessage("Invalid Username or Password");
mAlert.setPositiveButton("ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
}
});
mAlert.show();
mUserId.setText("");
mPassword.setText("");
}
}
});