0

我正在数据库中搜索用户输入。这是一个字典应用程序。我有一个切换按钮,允许用户在两​​种语言之间切换。它可以工作,但是当我切换到其他语言时它不起作用。基本上我想在按钮切换到另一种语言时应用不同的 sql 查询。

这是我的代码:

try {

        Cursor cursor = dictionary.getDictionaryDatabase().rawQuery("SELECT * FROM fr_definition JOIN fr_adresse_definition ON fr_definition.data_id = fr_adresse_definition.definition WHERE index_nom_adresse='"+word[0].toLowerCase().trim()+"'", null);

        cursor.moveToFirst();
        if (cursor.getCount() != 0) {

            if (word[1] == null || word[1].equals("English")) {
                translatedWord = cursor.getString(2);
            } else {

                 //dictionary.getDictionaryDatabase().rawQuery("SELECT * FROM en_definition JOIN en_adresse_definition ON en_definition.data_id = en_adresse_definition.definition WHERE index_nom_adresse='"+word[0].toLowerCase().trim()+"'", null);
                translatedWord = cursor.getString(1);
            }
        } else {
            translatedWord = "The word is not in database";
        }
        cursor.close();
    } catch (SQLiteException sqle) {
        translatedWord = "The word is not in database";
    }

    dictionary.close();
4

1 回答 1

0

这样的事情不会让您使用其他查询吗?

try {
    Cursor cursor;

    if (word[1] == null || word[1].equals("English")) {
         cursor = dictionary.getDictionaryDatabase().rawQuery("SELECT * FROM fr_definition JOIN fr_adresse_definition ON fr_definition.data_id = fr_adresse_definition.definition WHERE index_nom_adresse='"+word[0].toLowerCase().trim()+"'", null);
         cursor.moveToFirst();
         if (cursor.getCount() != 0) {
             translatedWord = cursor.getString(2);
         }
    } else {
         cursor = dictionary.getDictionaryDatabase().rawQuery("SELECT * FROM en_definition JOIN en_adresse_definition ON en_definition.data_id = en_adresse_definition.definition WHERE index_nom_adresse='"+word[0].toLowerCase().trim()+"'", null);
         cursor.moveToFirst();
         if (cursor.getCount() != 0) {
              translatedWord = cursor.getString(1);
         } 
    }

    cursor.close();
} catch (SQLiteException sqle) {
    translatedWord = "The word is not in database";
}

dictionary.close();
于 2013-04-06T14:30:31.170 回答