【发布时间】:2019-12-13 20:19:00
【问题描述】:
我正在尝试将我的 SQLite 数据库中的列中的字符串与我在使用游标和数据库助手时创建的另一个字符串进行比较。
当我运行应用程序时,不管数据库有什么,应用程序只进入 UserMenu.class
部分代码: (注释掉的东西是我在尝试各种东西。)
public void onClick(View v) {
String email = Username.getText().toString();
String pass = Password.getText().toString();
String role = " ";
String test2 = "Admin";
cursor = db.rawQuery("SELECT * FROM "+ DatabaseHelper.TABLE_NAME + " WHERE "+ DatabaseHelper.COL_3+ " =? AND "+ DatabaseHelper.COL_2+ "=?",new String[]{email, pass});
if (cursor!=null){
if (cursor.getCount()> 0){
db.rawQuery("SELECT * FROM "+ DatabaseHelper.TABLE_NAME + " WHERE "+ DatabaseHelper.COL_4+ " =?", new String[]{role});
if(role.equals(test2)) {
cursor.moveToNext();
Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_SHORT).show();
//cursor = db.rawQuery("SELECT * FROM "+ DatabaseHelper.TABLE_NAME + " WHERE "+ DatabaseHelper.COL_3+ " =?", new String[]{role2});
// Toast.makeText(getApplicationContext(),"Cursor count: "+cursor.getCount(),Toast.LENGTH_SHORT).show();
Intent i = new Intent(MainActivity.this, AdminMenu.class);
startActivity(i);
} else {
cursor.moveToNext();
//moveToUser();
Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_SHORT).show();
// = db.rawQuery("SELECT * FROM "+ DatabaseHelper.TABLE_NAME + " WHERE "+ DatabaseHelper.COL_3+ " =?", new String[]{role});
//Toast.makeText(getApplicationContext(),"Cursor count: "+cursor.getCount(),Toast.LENGTH_SHORT).show();
Intent i = new Intent(MainActivity.this, UserMenu.class);
startActivity(i);
}
} else {
Toast.makeText(getApplicationContext(),"Invalid email and/or password. Please try again.",Toast.LENGTH_SHORT).show();
}
}
}
【问题讨论】:
标签: java database sqlite android-studio