android - SQLite wont show results -
i'm using simple databasehandler-class, because want of things raqqueries. database correctly created. use:
public class databasehandler extends sqliteopenhelper { private static int database_version = 2; private static string database_create_table = null; private static string database_table = null; public databasehandler(context context, string dbname, string dbcreatetable, string dbtable) { super(context, dbname, null, database_version); database_create_table = dbcreatetable; database_table = dbtable; } // creating tables @override public void oncreate(sqlitedatabase db) { try { db.execsql(database_create_table); log.i("db created with: ", database_create_table); } catch (sqlexception e) { log.e("oncreate", e.getmessage()); } } // upgrading database @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { // drop older table if existed db.execsql("drop table if exists " + database_table); // create tables again oncreate(db); } public sqlitedatabase returndb() { return this.getwritabledatabase(); } }
in main thread do:
// db databasehandler dbhandler = new databasehandler( v.getcontext(), v.getcontext().getresources().getstring(r.string.database_name), v.getcontext().getresources().getstring(r.string.database_create_default_table), v.getcontext().getresources().getstring(r.string.database_default_table)); // db end sqlitedatabase db = dbhandler.returndb(); cursor cursor = db.rawquery("select * contacts;", null); log.e("cursor: ", cursor.tostring()); log.e("cursor count: ", string.valueof(cursor.getcount())); try { db.rawquery("insert contacts (contactname, phonenumber) values ('test', '123');", null); } catch (securityexception e) { log.e("error: ", e.getmessage()); } cursor cursor2 = db.rawquery("select * contacts;", null); log.e("cursor: ", cursor2.tostring()); log.e("cursor count: ", string.valueof(cursor2.getcount())); }
but get:
04-07 00:19:35.707: e/cursor:(6526): android.database.sqlite.sqlitecursor@42ea27f8 04-07 00:19:35.707: e/cursor count:(6526): 0 04-07 00:19:35.707: e/cursor:(6526): android.database.sqlite.sqlitecursor@42ea33c0 04-07 00:19:35.707: e/cursor count:(6526): 0
in return, knows why?
try this..
cursor cursor2 = db.rawquery("select * contacts;", null); cursor2.movetofirst(); log.e("cursor: ", cursor2.tostring()); log.e("cursor count: ", string.valueof(cursor2.getcount()));
Comments
Post a Comment