Android database can't update -
Android database can't update -
i'll seek update database can't update. insert correctly don't alter rows new ones.
mydatabase = getmydatabase();// this.getwritabledatabase(); contentvalues devices = new contentvalues(); devices.put(key_name, name); devices.put(key_address, address); devices.put(key_grade, grade); devices.put(key_array,gradearray); try{ mydatabase.insertorthrow(database_table, null, devices); } grab (sqliteconstraintexception e) { string = "'"+address+"'='"+key_address+"'"; mydatabase.update(database_table, devices, where,null); } mydatabase.close();
this code in function take different grade , gradearray values. strings.
database create statement:
string create = string.format("create table %s ( %s integer primary key autoincrement,"+ " %s text ,%s text not null unique , %s text not null, %s text);", database_table, key_row_id, key_name, key_address, key_grade, key_array);
string = "'"+address+"'='"+key_address+"'";
you're comparing literal literal here. remove ''
column name, e.g.
string = key_address + "='"+address+"'";
to avoid sql injection such, utilize parameters:
string = key_address + "=?"; mydatabase.update(database_table, devices, where, new string[] { address });
android database sqlite
Comments
Post a Comment