mercredi 29 avril 2015

Create SQL table, SQLite Exception

know this is a very elementary question, i keep on getting this error code on my logcat:

android.database.sqlite.SQLiteException: near "SELECT_id": syntax error (code 1): , while compiling: SELECT_id, name,password FROM GANDALF ORDER BY name

Would really need some advice, have tried looking at other create sqlite table post but couldnt solve it.

     public void onCreate(SQLiteDatabase db) {
     db.execSQL("CREATE TABLE gandalf " +
            "(_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,password TEXT, category TEXT);");

}

And try this too

     db.execSQL("CREATE TABLE books ( " +
                "id INTEGER PRIMARY KEY AUTOINCREMENT, " + 
                "name TEXT, "+
                "password TEXT, "+
                "category TEXT)");

Full code for datahelper public class DataHelp extends SQLiteOpenHelper{

private static final String dbname = "pass.db"; 
private static final int ver = 1;

public DataHelp(Context context) {
    super(context, dbname, null, ver);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
     db.execSQL("CREATE TABLE gandalf " +
            "(_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,password TEXT, category TEXT);");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
}

public void insertDB(String name, String pass){
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put("Name", name);
    cv.put("Pass", pass);
    db.insert("db", null, cv);
    db.close();
}

public Cursor getAll(){
    return (getReadableDatabase().rawQuery("SELECT_id, name," +
            "password FROM GANDALF ORDER BY name",null));
}

public String getName(Cursor c){
    return(c.getString(1));
}

 public String getPass(Cursor c) {
        return(c.getString(2));
      }

 public String getCat(Cursor c) {
        return(c.getString(3));
      }

}

Aucun commentaire:

Enregistrer un commentaire