sqlite:(1)near“)”:语法错误
我不明白,我认为(并且仍然如此)我把所有空间(等等)都需要
也许有人可以帮助我?
感谢您的时间
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 );
}
我以为我上面犯了一个错误(onCreate方法)......
其余的......
@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();
}
}
再次感谢!
而且我真的很抱歉这么多代码
答案 0 :(得分:2)
您的问题在CREATE TABLE SQL COMMAND
+ KEY_ID + " INTEGER PRIMARY KEY, " + KEY_REKORDAI + " TEXT," + " ) ";// remove semi column after TEXT
使用以下
更正CREATE TABLE SQL COMMAND
String CREATE_REKORDAI_TABLE = "CREATE TABLE " + TABLE_REKORDAI + " ( "
+ KEY_ID + " INTEGER PRIMARY KEY, " + KEY_REKORDAI + " TEXT" + " ) ";