android - The SQL database is not being created -
i trying create tables dynamically , access them when needed ... when run code neither giving errors or exceptons nor creating database ... debugging saw oncreate method called time when encounters getwritabledatabase()
.
here sqlopenhelper class -
package com.example.launch; import java.util.arraylist; import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.util.log; public class db extends sqliteopenhelper { sqlitedatabase db12; public db(context context) { super(context, null, null, 1); } public void oncreate(sqlitedatabase b) { b.execsql("create table if not exists sample1 (col1 text_type,col2 text_type,message text_type )"); } public void create(string name) { db12 = getwritabledatabase(); db12.execsql("create table if not exists " + name + "(col1 text_type,col2 text_type,message text_type )"); db12.close(); log.e("create", "successful"); } public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { } public void insert(string name, string message, string col1, string col2) { create(name); db12 = getwritabledatabase(); contentvalues v = new contentvalues(); v.put("col1", col1); v.put("col2", col2); v.put("message", message); db12.insert(name, null, v); log.e("insert", "may successful"); db12.close(); } public arraylist<string> getarray() { arraylist<string> tablelist = new arraylist<string>(); string sql_get_all_tables = "select name " + "sqlite_master type='table' order name"; db12 = getwritabledatabase(); log.e("here", "came"); cursor cursor = db12.rawquery(sql_get_all_tables, null); try { if (cursor.movetofirst()) ; { while (!cursor.isafterlast()) { tablelist.add(cursor.getstring(0)); cursor.movetonext(); } } } { cursor.close(); db12.close(); } return tablelist; } public string gettable(string name) { cursor cursor = null; string ss = ""; db12 = getwritabledatabase(); try { cursor = db12.rawquery("select * " + name, null); if (cursor.movetofirst()) { int col2in = cursor.getcolumnindex("col2"); int msg = cursor.getcolumnindex("message"); while (!cursor.isafterlast()) { if (cursor.getstring(col2in) == "1") { ss = ss + "/n " + name + " : " + cursor.getstring(msg); } else { ss = ss + "/n : " + cursor.getstring(msg); } } } } { cursor.close(); db12.close(); } return ss; } }
any appreciated ....
Comments
Post a Comment