[英]Java, SQLite, Insert data to Database
I have a SQLite database, with these parameters我有一个带有这些参数的 SQLite 数据库
private static final String TABLE_NAME = "people_table";
private static final String COL1 = "ID";
private static final String COL2 = "name";
private static final String COL3 = "anything";
Here's how it's created:这是它的创建方式:
String createTable = "CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
COL2 +" TEXT, " + COL3 + "TEXT)" ;
I'm trying to add data to the db, for both columns, my code is here:我正在尝试将数据添加到数据库中,对于两列,我的代码都在这里:
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL2, "item");
contentValues.put(COL3, "item2");
long result = db.insert(TABLE_NAME,null,contentValues);
if (result > 0) {
return true;
} else {
return false;
}
But it is not working, I have no idea why.但它不起作用,我不知道为什么。
Please, any advice?请问,有什么建议吗?
Your issue is that you have omitted a space so there is no column named anything , but instead a column named anythingTEXT您的问题是您省略了一个空格,因此没有名为any的列,而是名为anyTEXT的列
Change to use :-更改使用:-
String createTable = "CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
COL2 +" TEXT, " + COL3 + " TEXT)" ;
Then delete the App's data, or uninstall the App and rerun.然后删除应用程序的数据,或卸载应用程序并重新运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.