为什么我不能在sqLite中插入新行?

时间:2014-02-09 10:00:55

标签: android

我正在使用developer.android学习SQLite 我创建了这个类,如developer.android:

public class FeedReaderDbHelper extends SQLiteOpenHelper {
// If you change the database schema, you must increment the database version.
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "FeedReader.db";
public static final String sakht="CREATE TABLE english (ID INTEGER PRIMARY KEY,kalame TEXT,mani TEXT,marhale TEXT,taghir TEXT";
public static final String pak="DROP TABLE IF EXISTS english";
public FeedReaderDbHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
    db.execSQL(sakht);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // This database is only a cache for online data, so its upgrade policy is
    // to simply to discard the data and start over
    db.execSQL(pak);
    onCreate(db);
}
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    onUpgrade(db, oldVersion, newVersion);
}

}

我也像developer.android一样编写了插入方法。

FeedReaderDbHelper mDbHelper = new FeedReaderDbHelper(getApplicationContext());
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    ContentValues values = new ContentValues();
    Date now=new Date();
    values.put("ID", 1);
    values.put("kalame", "hello");
    values.put("mani", "salam");
    values.put("marhale", "1");
    values.put("taghir", now.getTime()+"");

long newRowID=db.insert("english", "taghir" , values);

但我的应用程序将被强制关闭
我该如何解决?

1 个答案:

答案 0 :(得分:0)

您的创建查询错误。试试下面的代码

public static final String sakht="CREATE TABLE english (ID INTEGER PRIMARY KEY, kalame TEXT, mani TEXT, marhale TEXT, taghir TEXT);";

你的看跌期权应该是 - values.put(" taghir",String.valueOf(now.getTime()));