0

I have the below code:

    ArrayList NumList = getIntent().getParcelableArrayListExtra ("name");
    ArrayList<String> results = new ArrayList<String>();
    SQLiteDatabase sampleDB = null;

    try {
        sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);

        sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
                SAMPLE_TABLE_NAME +
                " (FirstName VARCHAR);");

        sampleDB.execSQL("INSERT INTO " +
                SAMPLE_TABLE_NAME +
                " Values (NumList);");

What I am trying to do is to pass the NumList into the table. The above code shows an error saying "no such column: NumList)" How would I pass this information through?

4
  • sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " + SAMPLE_TABLE_NAME + " (FirstName VARCHAR);"); You have only one column in your table which is FirstName. Try to add NumList too. Commented Aug 14, 2012 at 8:41
  • I want the NumList to be stores in the FirstName column. Commented Aug 14, 2012 at 8:42
  • sampleDB.execSQL("INSERT INTO " + SAMPLE_TABLE_NAME + " Values (" + NumList[i] + ");"); You have to take NumList variable out. Commented Aug 14, 2012 at 8:47
  • I get the error: The type of the expression must be an array type but it resolved to ArrayList Commented Aug 14, 2012 at 8:52

2 Answers 2

2

Try this:

for(String str: NumList){
sampleDB.execSQL("INSERT INTO " +
            SAMPLE_TABLE_NAME +
            " ( FirstName ) Values ('"+str+"');");
}
Sign up to request clarification or add additional context in comments.

4 Comments

thanks that works, sorry to be a pain but any idea how I could retain the state of checkboxes after the app closes?
Use SharedPreferences to save the states.
how would I do this? I have tried but I can't seem to get it working
You save the states as boolean. If checked you save as true, if unchecked you save false. On launching the application you read them. if true you check if false you uncheck.
2

Try this one:

sampleDB.execSQL("INSERT INTO " +
            SAMPLE_TABLE_NAME +
            " ( FirstName ) Values ('"+NumList+"');");

4 Comments

thank you, that works :) is there anyway to display it as a list again or maybe automatically add a row for each value in the list?
my question is not fully answered, I would like to show the information as a list or add a new row for each value in the list
u have to put arraylist NumList in for loop
i answered again to ur question check my new answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.