dimanche 7 juin 2015

Update on Android SQLite problems

I have a problem when performing a routine update with SQLite from my application on Android, my code is as follows:

Categoria.java

public class Categoria implements Serializable {

private int idCategoria;
rivate String dscCategoria;    
private int colorEtiqueta;

public int getIdCategoria() {
    return idCategoria;
}

public void setIdCategoria(int idCategoria) {
    this.idCategoria = idCategoria;
}

public String getDscCategoria() {
    return dscCategoria;
}

public void setDscCategoria(String dscCategoria) {
    this.dscCategoria = dscCategoria;
}    

public int getColorEtiqueta() {
    return colorEtiqueta;
}

public void setColorEtiqueta(int colorEtiqueta) {
    this.colorEtiqueta = colorEtiqueta;
}}

Databasehelper.java

    public class DatabaseHelper {

    private Context context;

    public DatabaseHelper(Context context){
        this.context = context;
    }

    public void modificaCategoria(Categoria categoria){
            UseDatabaseHelper useDatabaseHelper = new UseDatabaseHelper(context, "MyDataBase", null, 1);
            SQLiteDatabase db = useDatabaseHelper.getWritableDatabase();
            try{
                if(db != null){
                    ContentValues contentValues = new ContentValues();
                    contentValues.put("dsccategoria", categoria.getDscCategoria());
                    contentValues.put("color", categoria.getColorEtiqueta());
                    db.update("Categorias", contentValues, "Where idcategoria=" + categoria.getIdCategoria(), null);
                }
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                if (db != null){
                    db.close();
                }
                if (useDatabaseHelper != null){
                    useDatabaseHelper.close();
                }
            }
        }
}

I have no errors in the execution, but no updating is done, any ideas?

Thanks.

PS: Sorry for my English.

Aucun commentaire:

Enregistrer un commentaire