Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6577589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:39:22+00:00 2026-05-25T15:39:22+00:00

I have a different arraylist with column names. I want to have a generatized

  • 0

I have a different arraylist with column names. I want to have a generatized create method that should create table based on the arraylist i have passed. Is it possible to have a structure with can create table dynamically. Please suggest any solution.

private static class OpenHelper extends SQLiteOpenHelper {

        OpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        System.out.println("openhelper1");

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.d("**DataHelper", "***********in oncreate");
        db.execSQL("CREATE TABLE " + TABLE_NAME + " (username TEXT,altnum TEXT,passkey TEXT,flag TEXT)");

    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w("Example", "Upgrading database, this will drop tables and recreate.");
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:39:22+00:00Added an answer on May 25, 2026 at 3:39 pm

    I created my own class to create tables and insert values in generatized manner.

    public void createDynamicDatabase(Context context,String tableName,ArrayList<String> title) {
    
                Log.i("INSIDE createLoginDatabase() Method","*************creatLoginDatabase*********");
                try {
    
                    int i;
                    String querryString;
                    myDataBase = context.openOrCreateDatabase("Db",Context.MODE_WORLD_WRITEABLE, null);         //Opens database in writable mode.
                    //System.out.println("Table Name : "+tableName.get(0));
    
                    querryString = title.get(0)+" VARCHAR(30),";
                    Log.d("**createDynamicDatabase", "in oncreate");
                    for(i=1;i<title.size()-1;i++)
                    {               
                        querryString += title.get(i);
                        querryString +=" VARCHAR(30)";
                        querryString +=",";
                    }
                    querryString+= title.get(i) +" VARCHAR(30)";
    
                    querryString = "CREATE TABLE IF NOT EXISTS " + tableName + "("+querryString+");";
    
                    System.out.println("Create Table Stmt : "+ querryString);
    
                    myDataBase.execSQL(querryString);
    
                } catch (SQLException ex) {
                    Log.i("CreateDB Exception ",ex.getMessage());
                }
            }
            public void insert(Context context,ArrayList<String> array_vals,ArrayList<String> title,String TABLE_NAME) {
                Log.d("Inside Insert","Insertion starts for table name: "+TABLE_NAME);
                myDataBase = context.openOrCreateDatabase("Db",Context.MODE_WORLD_WRITEABLE, null);         //Opens database in writable mode.
                String titleString=null;
                String markString= null;
                int i;
                titleString = title.get(0)+",";
                markString = "?,";
                Log.d("**createDynamicDatabase", "in oncreate");
                for(i=1;i<title.size()-1;i++)
                {               
                    titleString += title.get(i);
                    titleString +=",";
                    markString += "?,";
                }
                titleString+= title.get(i);
                markString += "?";
    
                //System.out.println("Title String: "+titleString);
                //System.out.println("Mark String: "+markString);
    
    
                INSERT="insert into "+ TABLE_NAME + "("+titleString+")"+ "values" +"("+markString+")";
                System.out.println("Insert statement: "+INSERT);
                //System.out.println("Array size iiiiii::: "+array_vals.size());
                //this.insertStmt = this.myDataBase.compileStatement(INSERT);
                int s=0;
    
                while(s<array_vals.size()){
    
                System.out.println("Size of array1"+array_vals.size());
                        //System.out.println("Size of array"+title.size());
                int j=1;
                this.insertStmt = this.myDataBase.compileStatement(INSERT);
                for(int k =0;k< title.size();k++)
                {
    
                    //System.out.println("Value of column "+title+" is "+array_vals.get(k+s));
                    //System.out.println("PRINT S:"+array_vals.get(k+s));
                    System.out.println("BindString: insertStmt.bindString("+j+","+ array_vals.get(k+s)+")");
                    insertStmt.bindString(j, array_vals.get(k+s));
    
    
    
                    j++;
                }
    
                s+=title.size();
    
                }
                insertStmt.executeInsert();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an arraylist that gets different type of values in it, 1st value->
I have 9 different ArrayList and I want to have a list of the
I have an arrayList of different types of players based on sports. I need
I have a datagrid, which gets filled by an ArrayList. I want one column
I have an ArrayList of objects that I need to sort in two different
I have a ArrayList made up of different elements imported from a db, made
I have different php output in jQuery-based tabs. This output is formed from database
I have different urls that points to the same code www.url1.com www.url2.com I need
I have noticed over the years that different developers have different criteria for what
I have an Arraylist of HashMap . Each HashMap element contains two columns: column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.