问题
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