0
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;
Is generating the following error:
android.database.sqlite.Sqliteexception: near "@fteste": syntax error (code 1): , while compiling: SELECT * FROM usuario WHERE email = [email protected] AND password = test123.
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);
}
Edit your question, providing details of the problem, just pasting the code makes it difficult to analyze and, consequently, help you solve. Enjoy and read [Ask]
– user28595