我正在工作sqlite.i成功创建数据库和table.and我也可以注册一些新用户 . 我也用户名写入登录功能只是这是我的代码的一部分
public String getSinlgeEntry(String username) {
Cursor cursor = db.query(usm_Users, null, " UserName=?",
new String[] { username }, null, null, null);
if (cursor.getCount() < 1) // UserName Not Exist
{
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String customername = cursor.getString(cursor
.getColumnIndex("UserName"));
cursor.close();
return customername;
}
String username=namefild.getText().toString();
String password=passwordfild.getText().toString();
String storedusername=loginDataBaseAdapter.getSinlgeEntry(username);
if(username.equals(storedusername))
{
Toast.makeText(MainActivity.this, "Congrats: Login Successfully", Toast.LENGTH_LONG).show();
Intent ii=new Intent(MainActivity.this,Home.class);
startActivity(ii);
}
else
if(username.equals("")){
Toast.makeText(MainActivity.this, "Please Enter Your Password", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(MainActivity.this, "Password Incorrect", Toast.LENGTH_LONG).show();
}
}
我可以检查登录只有username.how我可以写两个参数功能巫婆可以一起检查用户名和密码吗?
public String getSinlgeEntry(String username,String password) {
Cursor cursor = db.query(usm_Users, null, " UserName=?",
new String[] { username }, null, null, null);
if (cursor.getCount() < 1) // UserName Not Exist
{
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String customername = cursor.getString(cursor
.getColumnIndex("UserName"));
cursor.close();
return customername;
}
我必须改变我的光标 . 如果有人知道解决方案,请帮助我