编译我的查询时没有这样的列错误(代码1)

问题描述 投票:-2回答:2

我在公告表上有这些列:announceno(autoincrement),announceby(text),announcetitle(text),announcecontent(text)。

我的活动通过从微调器中选择标题来查看列表视图上的内容。所以我有这个查询,我需要从微调器获取标题并加载查询,而它等于标题。 “NEW TITLE”是旋转器的内容。

我有这个错误(更新):

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

我的查询(更新):

    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;
}

我的列表视图(更新):

    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());
            }}


    }
java mysql listview android-studio cursor
2个回答
0
投票

用单引号环绕title

String selectQuery = "SELECT * FROM " + TABLE_MESSAGE +" where " +
                     KEY_ANNOUNCETITLE + " = '"+title+"'";

0
投票

谢谢。原来我的TABLE应该是公告表而不是消息表。这就是为什么没有这样的专栏。

© www.soinside.com 2019 - 2024. All rights reserved.