Sqlite android.database.sqlite.Sqliteexception

Asked

Viewed 74 times

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>?

  • The problem must be in sqliteHelper.NOME_TABELA

  • You have a column called [email protected] in this table?

  • 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

  • Rafael Nena does not have a column called [email protected], I have a column called email.

  • Wakim already tried to do it this way but it went wrong.

  • Thiago tbm tried this way did not succeed

  • @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 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.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.