SQLiteDatabase error “sqlite: (1) near ”)“: syntax error”

佐手、 提交于 2019-12-14 04:26:19

问题


sqlite: (1) near ")": syntax error

I don't understand, I thought (and still do) that I put every space (and ect.) needed

maybe someone could help me?

thanks for your time

public class DatabaseHandler extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 3;
    private static final String DATABASE_NAME = "rekordai";
    private static final String TABLE_REKORDAI = "rekordai";

    private static final String KEY_ID = "id";
    private static final String KEY_REKORDAI = "rekordai";

    public DatabaseHandler(Context context){
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_REKORDAI_TABLE = "CREATE TABLE " + TABLE_REKORDAI + " ( " 
                + KEY_ID + " INTEGER PRIMARY KEY, " + KEY_REKORDAI + " TEXT," + " ) ";
        db.execSQL( CREATE_REKORDAI_TABLE );
    }

I thought I made a mistake above (onCreate method)...

the rest...


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {
        db.execSQL( "DROP TABLE IF EXISTS " + TABLE_REKORDAI );

        onCreate(db);

    }
    void addRekordas(Rekordas r){
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues v = new ContentValues();
        v.put(KEY_REKORDAI, r.getRekordas());

        db.insert(TABLE_REKORDAI, null, v);
        db.close();
    }
    Rekordas getRekordas(int id){
        SQLiteDatabase db = this.getReadableDatabase();

        Cursor c = db.query(TABLE_REKORDAI, new String[]{ KEY_ID, KEY_REKORDAI},
                KEY_ID + " = ?", new String[]{ String.valueOf(id)}, null, null, null, null);
        if(c != null){
            c.moveToFirst();
        }   
        Rekordas r = new Rekordas(Integer.parseInt(c.getString(0), Integer.parseInt(c.getString(1))));

        return r;       
    }

    public ArrayList<Rekordas> getAllRekordas(){                         // Patikrinti veliau
        String selectQuery = "SELECT  * FROM " + TABLE_REKORDAI;
        ArrayList<Rekordas> rekordaiList = new ArrayList<Rekordas>();

        SQLiteDatabase db = this.getWritableDatabase(); 
        Cursor cursor = db.rawQuery(selectQuery, null); 

        if (cursor.moveToFirst()){
            do{
                Rekordas r = new Rekordas();
                r.setId(Integer.parseInt(cursor.getString(0)));
                r.setRekordas(Integer.parseInt(cursor.getString(1)));
                rekordaiList.add(r);
            } while(cursor.moveToNext());


        }
        return rekordaiList;
    }

    public int upgradeRakordas(Rekordas r){
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues v = new ContentValues();
        v.put(KEY_REKORDAI, r.getRekordas());

        return db.update(TABLE_REKORDAI, v, KEY_ID + " = ?", new String[]{String.valueOf(r.getId())});
    }
    public void deleteRekordas(Rekordas r){
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(TABLE_REKORDAI, KEY_ID + " = ?", new String[]{String.valueOf(r.getId())});
        db.close();
    }
    public int getRekordaiCount(){
        SQLiteDatabase db = this.getReadableDatabase();
        String countQuery = "SELECT  * FROM " + TABLE_REKORDAI;
        Cursor c = db.rawQuery(countQuery, null);
        c.close();

        return c.getCount();
    }
}

thanks again! and I'm really sorry for soo much code


回答1:


Your issue is here CREATE TABLE SQL COMMAND

  + KEY_ID + " INTEGER PRIMARY KEY, " + KEY_REKORDAI + " TEXT," + " ) ";// remove semi column after TEXT 

Correct CREATE TABLE SQL COMMAND with below

 String CREATE_REKORDAI_TABLE = "CREATE TABLE " + TABLE_REKORDAI + " ( " 
            + KEY_ID + " INTEGER PRIMARY KEY, " + KEY_REKORDAI + " TEXT" + " ) ";


来源:https://stackoverflow.com/questions/23032024/sqlitedatabase-error-sqlite-1-near-syntax-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!