-1

I have these column on my announcement table: announceno(autoincrement), announceby(text), announcetitle(text), announcecontent(text).

My activity views the content on listview by selecting the title from spinner. So I have this query where I need to get the title from the spinner and load the query while its equal to the title. "NEW TITLE" is the content of spinner.

I have this error(updated):

android.database.sqlite.SQLiteException: no such column: announcetitle (code 1): , while compiling: SELECT * FROM tablemessage where announcetitle =?

My query(updated):

    public Cursor announcements (String title){
    SQLiteDatabase db = DBHelper.getWritableDatabase();

    String selectQuery = "SELECT * FROM " + TABLE_MESSAGE +" where " +
            KEY_ANNOUNCETITLE + " =  ?";
    Cursor data = db.rawQuery(selectQuery , new String[]{title});


    return data;
}

My Listview(updated):

    public void myMethod() {
    if(spnr1.getSelectedItem().toString() == "--SELECT TITLE--"){


    }else{

        ArrayList<String> theList = new ArrayList<>();

        String a = et16.getText().toString();
        String h = spnr1.getSelectedItem().toString();
        Cursor data = db.announcements(h);


            if (data.moveToFirst()) {
                do {

                    theList.add(data.getString(3));
                    ListAdapter listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, theList);
                    lv.setAdapter(listAdapter);
                } while (data.moveToNext());
            }}


    }
Aya Sato
  • 29
  • 1
  • 9
  • [You are vulnerable to SQL injection](https://stackoverflow.com/questions/1582161/how-does-a-preparedstatement-avoid-or-prevent-sql-injection) – luk2302 Dec 25 '17 at 12:37
  • 1
    Im not into complicated stuffs yet. I just want my app runnable. – Aya Sato Dec 25 '17 at 13:22

1 Answers1

0

Thanks. Turns out that my TABLE is supposed to be announcement table not message table. Thats why theres no such column.

Aya Sato
  • 29
  • 1
  • 9