Database Handler in Realm for Android -
i trying implement realm in android. there way implement database handler in sqlite? every samples found in ui , under button clicks. there no pure implementation on seperate database file.
i have database handler class below:
public class databasehandler extends sqliteopenhelper { private static final int database_version = 1; private static final string database_name = "mytrain"; private static final string table_route = "route"; private static final string column_id = "id"; private static final string column_routename = "routename"; private static final string column_remarks = "remarks"; public databasehandler(context context) { super(context, database_name, null, database_version); } @override public void oncreate(sqlitedatabase db) { string create_route_table = "create table if not exists " + table_route + "("+column_id+" integer primary key," + column_routename+" text,"+column_remarks+" text)"; db.execsql(create_route_table); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { db.execsql("drop table if exists " + table_route); oncreate(db); } //to insert data public void addroute(int id, string routename, string remarks) { sqlitedatabase sqlitedatabase = this.getwritabledatabase(); contentvalues contentvalues = new contentvalues(); contentvalues.put(column_id, id); contentvalues.put(column_routename, routename); contentvalues.put(column_remarks, remarks); sqlitedatabase.insert(table_route, column_id, contentvalues); sqlitedatabase.close(); } //other crud operation functions lies here.... }
i want make similar functions , database handler class dedicated database stuffs..
so, how implement similar feature in realm database..
Comments
Post a Comment