I have created an activity where the user is prompted to enter their username and password, which is then checked against the database and if the return is true, it will log them in.
I have a login method in my DB.java class, which is a public boolean that returns true or false depending on if it's matched.
I then have a login class to handle the form.
DB.java
public boolean Login(String username, String password, SQLiteDatabase db) throws SQLException
{
Cursor mCursor = db.rawQuery("SELECT * FROM " + Table + " WHERE username=? AND password=?", new String[]{username,password});
if (mCursor != null) {
if(mCursor.getCount() > 0)
{
return true;
}
}
return false;
}
Login.java
public class Login extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
final EditText usernameET=(EditText)findViewById(R.id.usernameET);
final EditText passwordET=(EditText)findViewById(R.id.passwordET);
final Button loginBTN=(Button)findViewById(R.id.loginBTN);
DB db = new DB(this);
loginBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String usernamee = usernameET.getText().toString();
String password = passwordET.getText().toString();
***CHECK LOGIN HERE***
}
});
}
}
Basically I have tried using the Login method in Login.java from DB.java like so
db.Login(username, password, db);
However I guess it's recognising the second 'db' as the class, not the database. So do I need to declare and SQLiteDatabase to put in as the second 'db' or am I doing this completely wrong?
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire