Best practices for working with multiple tables

后端 未结 4 1511
無奈伤痛
無奈伤痛 2021-01-29 22:45

I use a database with multiple tables in my application. I have an XML parser which needs to write data to two tables while parsing. I created two database adapters for both tab

4条回答
  •  旧巷少年郎
    2021-01-29 23:10

    I'm a bit late maybe but i always open my database, not my table. So this form me as no sense.

        firstTable.open();
        secondTable.open(); 
    

    Rather do this.

        dataBase.getWritableDatabase();
    

    then if you want to update juste chose the table:

    public int updateTotal (int id, Jours jour){
        ContentValues values = new ContentValues();
    
        values.put(COL_TOTAL,Total );
    
        //update the table you want
        return bdd.update(TABLE_NAME, values, COL_JOUR + " = " + id, null);
    }
    

    And that's all. Hope it can help other people

提交回复
热议问题