Note that there are some explanatory texts on larger screens.

plurals
  1. POI Can't Update table with ormlite android
    text
    copied!<p>The problem is that I have a table product and my update script doesn't work aparently. It allwas return false.</p> <p><strong>Product.class</strong></p> <pre><code>@DatabaseTable(tableName = "Product") public class Product { @DatabaseField(index = true, generatedId = true) private int productId; @DatabaseField private String name; @DatabaseField private int quantity; //@DatabaseField(canBeNull = true) //private Integer categorie; //http://logic-explained.blogspot.com.ar/2011/12/using-ormlite-in-android-projects.html @DatabaseField private int categorie; //@ForeignCollectionField //private ForeignCollection&lt;Categorie&gt; itemsCategorie; @DatabaseField private String description; @DatabaseField private String photo; Product() { } public Product(int productId, String name, int quantity, int categorie, String description, String photo) { super(); this.productId = productId; this.name = name; this.quantity = quantity; this.categorie = categorie; this.description = description; this.photo = photo; } public void setDescription(String description) { this.description = description; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return description; } public void setAddress(String address) { this.description = address; } public int getProductId() { return productId; } public void setProductId(int productId) { this.productId = productId; } public int getQuantity() { return quantity; } public void setQuantity(int quantity) { this.quantity = quantity; } public int getCategorie() { return categorie; } public void setCategorie(int categorie) { this.categorie = categorie; } public String getPhoto() { return photo; } public void setPhoto(String photo) { this.photo = photo; } public CharSequence getDesc() { return null; } } </code></pre> <p><strong>my script updateProduct</strong></p> <pre><code>public boolean updateProduct(Product p) { boolean ret = false; if (productDao != null) { try { productDao = getDao(Product.class); UpdateBuilder&lt;Product, Integer&gt; updateBuilder = productDao .updateBuilder(); updateBuilder.updateColumnValue("name", p.getName()); updateBuilder.updateColumnValue("quantity", p.getQuantity()); updateBuilder.updateColumnValue("categorie", p.getCategorie()); updateBuilder.updateColumnValue("description", p.getDesc()); updateBuilder.updateColumnValue("photo", p.getPhoto()); // but only update the rows where the description is some value updateBuilder.where().eq("productId", p.getProductId()); // actually perform the update String str = updateBuilder.prepareStatementString(); // UPDATE `Product` SET `name` = 'gcd' ,`quantity` = 1 // ,`categorie` = 1 ,`description` = ? ,`photo` = '' WHERE // `productId` = 0 if (productDao.update(updateBuilder.prepare()) != 1) { ret = false; } else { productDao.refresh(p); ret = true; } } catch (Exception e) { ret = false; e.printStackTrace(); } } return ret; } </code></pre> <p><strong>then I call it with a function like this, but allways return false :(</strong></p> <pre><code>public boolean updateProduct(Product p) { boolean ret = false; try { ret = getHelper().updateProduct(p); } catch (Exception e) { e.printStackTrace(); ret =false; } return ret; } </code></pre> <p>I can create and delete but I can not update . I tried everything. If you please take a moment to answer my question I will appreciate.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload