0
I’m making the following mistake:
android.database.sqlite.Sqliteexception: near "@test": syntax error (code 1): , while compiling: SELECT [email protected], test FROM usuario WHERE email = '[email protected]' AND password = 'test' ;
@Override
public User buscarEmailSenha(String email, String senha) {
User user = null;
Cursor cursor;
String sql = sqliteHelper.NOME_TABELA + " WHERE email = '" + email
+ "' AND senha = '"+ senha +"' ;";
String [] args = new String[] {email, senha};
cursor = abrirBanco().query(sql, args, null, null, null, null, null);
if(cursor.moveToFirst()) {
user = new User();
user.setEmail(cursor.getString(cursor.getColumnIndex("email")));
user.setSenha(cursor.getString(cursor.getColumnIndex("senha")));
}
if (cursor != null)
fecharBanco();
return user;
}
Douglas, it seems to me that the contents of
sqliteHelper.NOME_TABELA
is not with a correct value to build an SQL query... Could you check if its content should not be:SELECT email, senha FROM <NOME_DA_TABELA>
?– Wakim
The problem must be in
sqliteHelper.NOME_TABELA
– Maniero
You have a column called [email protected] in this table?
– Rafael Mena Barreto
Another detail, if you pass the fields as parameters String [] args = new String[] {email, password}; no need to acidify in SQL : WHERE email = '" + email + "' AND password = '"+ password +"' ;" . In this case it is used ? in place of the parameter
– Thiago Luiz Domacoski
Rafael Nena does not have a column called [email protected], I have a column called email.
– Douglas William
Wakim already tried to do it this way but it went wrong.
– Douglas William
Thiago tbm tried this way did not succeed
– Douglas William
@Douglaswilliam then his SQL is wrong. You have to do: select column1, column2, column3 FROM table WHERE column1 (or 2) = 'given that you want to search';
– Rafael Mena Barreto
Rafael am doing as follows: String sql = "SELECT * FROM " + sqliteHelper.NOME_TABELA + " WHERE email = '" + email + "' AND password = '" + password + "';"; so it gives error: java.lang.Illegalargumentexception: Cannot bind argument at index 2 because the index is out of range. The statement has 0 Parameters. ie according to this outside index, has no parameters, these parameters are not coming.
– Douglas William