我想插入现有应用程序数据表的应用程序类别。我不知道我做的是否正确,但在我做的事情中我也得到了这个错误。
我应该如何正确地做到这一点?
主要活动
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
builder.setTitle("Please Select Category of : " + AppName);
builder.setItems(shareItems,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
// TODO Auto-generated method stub
String itemz = String.valueOf(shareItems[item]);
mySQLiteAdapter.insertcategory(AppName, itemz);
}
});
AlertDialog shareAlert = builder.create();
shareAlert.show();
处理程序
public long insertcategory(String AppName, String itemz) {
// TODO Auto-generated method stub
Cursor crack = sqlitedb.rawQuery("INSERT INTO " + KEY_CATEGORY
+ " VALUES ( ' " + itemz + " ' ) WHERE " + KEY_NAME
+ " LIKE ?", new String[] { "%" + AppName+ "%" });
return 0;
}
更新的查询 这是我用来更新表的。itemz 将值设为“游戏”,但未更新
public long insertcategory(String AppName, String itemz) {
// TODO Auto-generated method stub
ContentValues values = new ContentValues();
values.put(KEY_CATEGORY, itemz);
return sqlitedb.update(MYDATABASE_TABLE, values, KEY_NAME + " LIKE ?",
new String[] { "%" + AppName + "%" });
}
表创建为
private static final String SCRIPT_CREATE_DATABASE = "create table "
+ MYDATABASE_TABLE + " (" + KEY_ID
+ " integer primary key autoincrement, " + KEY_NAME
+ " text not null, " + KEY_PACK + " text not null, " + KEY_PERM
+ " text not null, " + KEY_LEVEL + " text not null, "
+ KEY_CATEGORY + " text);";