Saturday, 15 February 2014

sqlite - database is locked in getReadableDatabase() android -



sqlite - database is locked in getReadableDatabase() android -

in app getting database locked.

i tried using solutions provided in other posts not found suitable solution why posting question.

here oncreate

dbadapter db = new dbadapter(this.getapplicationcontext()); dialoge = new progress_dialog(this); dialoge.setcancelable(false); seek { db.createdatabase(); } grab (ioexception e) { e.printstacktrace(); }

and here create database method

public void createdatabase() throws ioexception{ boolean dbexist = checkdatabase(); if(!dbexist){ this.getreadabledatabase(); seek { copydatabase(); } grab (ioexception e) { e.printstacktrace(); throw new error("error copying database"); } } }

and below checkdatabase method

private boolean checkdatabase(){ sqlitedatabase checkdb = null; try{ string mypath = db_path + db_name; string mypath2 = db_path + db_name2; checkdb = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readwrite); if(checkdb != null){ checkdb.close(); } checkdb = sqlitedatabase.opendatabase(mypath2, null, sqlitedatabase.open_readwrite); }catch(sqliteexception e){ // e.printstacktrace(); //database does't exist yet. system.out.print("sqliteexception "+e.tostring()); } if(checkdb != null){ checkdb.close(); } homecoming checkdb != null ? true : false; }

please help me in this.

the "locking" occurring because attempting open multiple sqlitedatabase instances. create sqlitedatabase singleton described in post.

android sqlite

No comments:

Post a Comment