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

0

I'm trying to make SELECT below passing a value as a parameter in the search, but it still gives the same error.

  

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

What is the problem with my 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 the fields in the 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;
}
    
asked by anonymous 09.11.2018 / 07:32

1 answer

1

The SQL language does not have a command called SQL, there is a SELECT so probably what you wanted to use was:

SELECT * FROM Employers WHERE id = ?

Normally the error message is very informative about the error. Whenever you read it carefully you find the error without major problems. Only on this page does the error appear 5 times. Programming is attention to detail, not just copying and pasting without paying attention to what is appearing.

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

    
09.11.2018 / 09:38