This method of my activity:
private void loginEmailSenha() {
editTextEmailLogin.setError(null);
editTextSenhaLogin.setError(null);
controllerUsuario = new ControllerUsuario(this);
String email = editTextEmailLogin.getText().toString();
String senha = editTextSenhaLogin.getText().toString();
boolean cancel = false;
View focusView = null;
if (TextUtils.isEmpty(email)) {
editTextEmailLogin.setError(getString(R.string.error_field));
focusView = editTextEmailLogin;
cancel = true;
}
if (TextUtils.isEmpty(senha)) {
editTextSenhaLogin.setError(getString(R.string.error_field));
focusView = editTextSenhaLogin;
cancel = true;
}
if (cancel) {
focusView.requestFocus();
} else {
controllerUsuario.buscarEmailSenha(email, senha);
Intent intent1 = new Intent(getApplicationContext(), OptionsUserActivity.class);
startActivity(intent1);
limparCampos();
}
}
controller method:
public User buscarEmailSenha(String email, String senha) {
return ir.buscarEmailSenha(email, senha);
}
method of my repository:
@Override
public User buscarEmailSenha(String email, String senha) {
User user = null;
Cursor cursor = abrirBanco().rawQuery("SELECT * FROM " + SqliteHelper.NOME_TABELA + " WHERE " +
sqliteHelper.EMAIL + " = '" + email + "' AND " + sqliteHelper.SENHA + " = '" + senha + "'", new String[]{email, senha} );
if(cursor.moveToFirst()) {
user = new User();
user.setEmail(cursor.getString(cursor.getColumnIndex("email")));
user.setSenha(cursor.getString(cursor.getColumnIndex("senha")));
}
return user;
You are generating the following error:
android.database.sqlite.SQLiteException: near "@fteste": syntax error (code 1):, while compiling: SELECT * FROM user WHERE email = [email protected] AND password = teste123.
Class SqliHelper
public static final String NOME_TABELA = "usuario";
public static final String NOME = "nome";
public static final String EMAIL = "email";
public static final String TELEFONE = "telefone";
public static final String SENHA = "senha";
public static final String COLUNA_ID = "_id";
public static final String TABLE_USER = "CREATE TABLE " + NOME_TABELA "( "
COLUNA_ID + " INTEGER PRIMARY KEY NOT NULL, "
NOME + " TEXT NOT NULL,"
EMAIL + " TEXT NOT NULL,"
TELEFONE + " TEXT NOT NULL,"
SENHA + " TEXT NOT NULL)";
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_USER);
db.execSQL(TABLE_CARONA);
}