top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Android: add table to database through code dynamically

+3 votes
401 views

I want to add table to the database dynamically through code on runtime. Note: I want to add tables at any point of time.

posted Aug 17, 2016 by Akshay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

You can use the below code. First, you should get the writable database and then drop the table if it is already there and create a new table.

dbs = this.getWritableDatabase();
dbs.execSQL("DROP TABLE IF EXISTS " + Table_Name);
dbs.execSQL("CREATE TABLE " + Table_Name + "(" + CID + " TEXT PRIMARY KEY, " + DName + " TEXT);");

Hope this helps!

answer Aug 24, 2016 by Vinod Kumar K V
Similar Questions
+2 votes

I have a data collection that is associated with a list of EditText. The data is dynamically retrieved. So, how would I access EditText dynamically and associate the value from the collection.

EditText editText = (EditText) findViewById(<How to pass id dynamically?>);
editText.setText("<my value here>");
0 votes

I have created a JAVA class exposing native API. I have kept this class in _frameworks/base/core/java/com/myDomain/myPackage/myClass.java_ and for this i have already created JNI C code files and their entries in required make files.

But after building the SDK, it didn't include expected package _com.myDomain.myPackage_.

Is there any specific configuration file(s) where I would have to make entries to include it in Android SDK, or the place is incorrect where currently class files is kept.

0 votes

Eg: If I want to send a message to destination number "**********", then what is the correct code to do it?

...