我真的很抱歉問這個愚蠢的問題。過去1小時,我一直在探究這個錯誤,無法從我眼中發現問題。如果有人能幫我找到問題,我會很感激。我知道這不是一個錯誤處理博客,但我沒有選擇。以下是我的DB代碼:語法錯誤使用sqlite
private static final String DATABASE_NAME = "RCdata";
private static final String DATABASE_TABLE = "events";
private static final int DATABASE_VERSION = 1;
private static final String TAG = "RCDataBaseAdapter";
private static final String KEY_ROWID = "_id";
private static final String KEY_EVENT = "eventsname";
private static final String KEY_DESCRIPTION ="description";
// Database creation sql statement
private static final String DATABASE_CREATE_EVENTS =
"create table events (_id integer primary key autoincrement, "
+ "eventsname text not null, "
+ "description text not null);";
private Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public RCDatabaseAdapter(Context ctx)
{
//super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
this.context = ctx;
DBHelper = new DatabaseHelper(context);
// TODO Auto-generated constructor stub
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(DATABASE_CREATE_EVENTS);
//db.execSQL(DATABASE_CREATE_Priests);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS Events");
onCreate(db);
}
}
//---opens the database---
public RCDatabaseAdapter open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
//---closes the database---
public void close()
{
DBHelper.close();
}
public long insertEvent(String eventname, String description)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_EVENT, eventname);
initialValues.put(KEY_DESCRIPTION, description);
return db.insert(DATABASE_TABLE, null, initialValues);
}
//---deletes a particular event---
public boolean deleteEvent(long rowId)
{
return db.delete(DATABASE_CREATE_EVENTS, KEY_ROWID +
"=" + rowId, null) > 0;
}
public Cursor getAllTitles()
{
return db.query(DATABASE_CREATE_EVENTS, new String[] {
KEY_ROWID,
KEY_EVENT,
KEY_DESCRIPTION},
null,
null,
null,
null,
null);
}
//---retrieves a particular title---
public Cursor getEvent(long rowId) throws SQLException
{
Cursor mCursor =
db.query(true, DATABASE_CREATE_EVENTS, new String[] {
KEY_ROWID,
KEY_EVENT,
KEY_DESCRIPTION
},
KEY_ROWID + "=" + rowId,
null,
null,
null,
null,
null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
我收到以下錯誤:
near 「create」: syntax error: ,
while compiling: SELECT _id,
eventsname, description
FROM create table events (_id
integer primary key
autoincrement, eventsname
text not null, description text
not null);
您可以在使用DATABASE_CREATE_Events的地方添加代碼嗎?好像你正在嘗試從表中「選擇」數據,同時傳遞一個'create'查詢。 – abhinav
我編輯了上面的代碼。感謝您的發起 – user1031746
DATABASE_CREATE_EVENTS我已將名稱更改爲全部大寫,以解決可能存在的問題,但仍然收到相同的錯誤。 – user1031746