0

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

0

1 Answer 1

3

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" + " ) ";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.