i want to insert category of the application of the existing table of application data. I do not know if im doing it correct, but in what i am doing i get this error as well.
how should i do it correctly?
Mainactivity
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();
Handler
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;
}
updated query This is what i used to update the table. itemz gets the value as 'Game' but it does not getting updated
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 + "%" });
}
Table created as
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);";
The INSERT command does not have a WHERE clause because it inserts a completely new record.
It appears you want to set/change the value in an existing record. This would be done with an UPDATE command:
UPDATE MyTable SET category = 'Entertainment' WHERE name LIKE ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With