我希望我的数据库创建一次,它不会改变,但是当我在onCreate()时我无法创建数据......
public class EventsData extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "events.db";
private static final int DATABASE_VERSION = 1;
public EventsData(Context ctx) {
super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + _ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + TIME
+ " TEXT NOT NULL," + TITLE + " TEXT NOT NULL);");
//This doesn't work..
db.execSQL("INSERT INTO"+TABLE_NAME+"VALUES(null, 'hello', 'android');");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
答案 0 :(得分:4)
该行
db.execSQL("INSERT INTO"+TABLE_NAME+"VALUES(null, 'hello', 'android');
缺少TABLE_NAME周围的空格。如果您执行此行,则无法正常工作。
答案 1 :(得分:0)
1>你打开数据库了吗?
2 - ;另外,创建另一个具有openDatabase,createTable,deleteTable,insertValues等实用方法的类。
INSERT STATEMENT的示例语法
databaseDb.execSQL(INSERT INTO TABLE_NAME值('Chiranjib','Banerjee',1););