Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting to pre-existing SQLite Database Android
    primarykey
    data
    text
    <p>Okay so my android app makes use of a pre-existing database, which I access using this</p> <p><a href="http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/" rel="nofollow">http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/</a></p> <p>Now I have no problem reading data from the database, but I cannot seem to add to it. The problem is the database file is never updated, only the instance of the database I have running at the time. I need the changes I make to the database to be permanent, so I tried to serialize the instance of the database, but found that it cannot be done. I think that after I add to the instance of my database, I need to export this to a file, an with it overwrite the database file. I'm not sure how I would go about and have read every comment from the site above and have gone through countless post here as well. </p> <p>I could be wrong but that's the only way I can imagine it being done. </p> <pre><code>public void addTenantWithoutProperty(String name, String email, String phone){ //This method reads from my database ArrayList&lt;Tenants&gt; tenants = (ArrayList&lt;Tenants&gt;) getAllTenants(); //Checks data in the database before I try add to it for(int i = 0;i &lt; tenants.size();i++){ String name; name = tenants.get(i).getName(); System.out.println(i + " before " + names); } //I have also tried adding to it using ContentValues, but it makes no difference String tenantsql = "INSERT INTO tenants (name, phone, email) VALUES ('" + name + "','" + phone + "','" + email + "')"; myDataBase.execSQL(tenantsql); tenants = (ArrayList&lt;Tenants&gt;) getAllTenants(); //checks data in database after insertion for(int i = 0;i &lt; tenants.size();i++){ String names; names = tenants.get(i).getName(); System.out.println(i + " after " + names); } } </code></pre> <p>This is called on a button click, and the output shows that the data is being added, but it does not cause a permanent change in the database. How can I get around this? Any help at all would be greatly appreciated </p> <p>EDIT: Resolved! The if statment in the createDataBase() read if(!dbExist), changed to if(dbExist) and works fine. Problem was that even if the database existed, it was being overwritten by the database file in my assets folder. Thanks for your replies regardless </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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