android.database.sqlite.Sqliteexception: near "SQL": syntax error (code 1): , while compiling: SQL * FROM Employers WHERE id =?

Asked

Viewed 270 times

0

I’m trying to do the SELECT below passing a value as parameter in the query, only it keeps giving the same error.

android.database.sqlite.Sqliteexception: near "SQL": syntax error (code 1): , while compiling: SQL * FROM Employers WHERE id = ?

What’s wrong with mine SELECT?

public Employer getEmployerProfile(String parameter) {
     String sql = "SQL * FROM Employers WHERE id = ?";

    SQLiteDatabase db = getReadableDatabase();

    Cursor c = db.rawQuery(sql, new String[]{parameter});

    c.moveToFirst();

    Employer employerProfile = new Employer();
    employerProfile.setName(c.getString(c.getColumnIndex("name")));
    employerProfile.setAddress(c.getString(c.getColumnIndex("address")));


    return employerProfile;
}

Format of fields in table:

private String createTableEmployers() {
    String sql = "CREATE TABLE Employers (id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT NOT NULL, address TEXT, status TEXT, confirmationStatus TEXT)";
    return sql;
}

1 answer

2


SQL language does not have a command called SQL, there is a SELECT then probably what I wanted to use was:

SELECT * FROM Employers WHERE id = ?

I put in the Github for future reference.

Usually the error message is very informative about the error. Whenever you read it carefully you already find the error without major problems. Only on this page the error appears 5 times. Programming is attention to detail, not just copy and paste without paying attention to what is appearing.

This code can be simplified, but this is another subject.

  • Thank you, it was lack of attention anyway. I think I was already addicted to the error. How can I simplify the code?

Browser other questions tagged

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