创建表示数据库表的对象

时间:2010-10-16 15:19:43

标签: android sqlite

我正在开发一个Android应用程序。

我想知道是否真的有必要创建表示来自SQLite数据库的表的对象。

我正在实现insert方法,而是使用表的特定对象,也许我可以使用HashMap。这个Hashmap将是该方法的参数。

public boolean insertEntry(HashMap entry) {

   ...
   String name = entry.get(Constants.COLUMN_NAME);
   ...
}

您怎么看?

1 个答案:

答案 0 :(得分:1)

我也使用HashMap在db中呈现数据对象,在表数据对象中扩展HashMap可能很容易阅读,例如:

public class TableObjectClass extends HashMap<String, String>{

    /* Define column of table object here */
    public static final String KEY_COLUMN_ID         = "id";            /* ID of record */
    public static final String KEY_COLUMN_OTHER      = "version";    /* Define other column */


    /* Define public method to set/get properties of table object, example */
    public String getID(){
        return this.get(KEY_COLUMN_ID);
    }

    public void setID(String strID){
        this.put(KEY_COLUMN_ID, strID);
    }

}
相关问题