I'm writing an android app where I have a java class which should represent a Table in DB.
class Table1 {
String row1;
String row2;
}
If I have to create a table in database I should do something like this.
mydatabase.execSQL("CREATE TABLE IF NOT EXISTS Table1(row1 VARCHAR,row2 VARCHAR);");
But the problem here is I'm duplicating the class structure in the SQL query. This is error prone and will require changes at multiple places whenever I need to change the attributes of the table. Is there a better way to do this. Something like mydatabase.createTableFrom(Table1.class)
that I could use instead?
Aucun commentaire:
Enregistrer un commentaire