How To Use External Sqlite in Android -


i learning android have doubt how use external sqlite manager (add on in firefox) in android studio

or

please how use 2 table names in sqlite example :user table , admin table

you can put database schema table design , may data in tables

to 1 mb in assets folder , when create instance of sqlite manager

copy assets data/data/packagename/databases/

first check database copied or not using code

private static string db_path = "/data/data/packagename/databases/"; private static string db_name = "dbname.db";  private boolean checkdatabase() {     sqlitedatabase checkdb = null;     try {         string mypath = db_path + db_name;         checkdb = sqlitedatabase.opendatabase(mypath, null,                 sqlitedatabase.open_readwrite);         if(checkdb.getversion() < database_version){             onupgrade(checkdb, checkdb.getversion(), database_version);         }     } catch (sqliteexception e) {     }     if (checkdb != null) {         checkdb.close();     }     return checkdb != null ? true : false; } 

if not exist then

private void copydatabase() throws ioexception {     // open local db input stream     inputstream myinput = mcontext.getassets().open(db_name);     // path created empty db     string outfilename = db_path + db_name;     // open empty db output stream      outputstream myoutput = new fileoutputstream(outfilename);     // transfer bytes inputfile outputfile     byte[] buffer = new byte[1024];     int length;     while ((length = myinput.read(buffer)) > 0) {         myoutput.write(buffer, 0, length);     }     // close streams     myoutput.flush();     myoutput.close();     myinput.close();  } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -