“错误:列不存在”使用现有列

时间:2022-09-25 23:16:13

I have the following java function. When I enter ingredientNaam as 'Banaan' it gives me the error:

我有以下java函数。当我输入ingredientNaam作为'Banaan'时,它给了我错误:

column does not exist.

列不存在。

However, the column does exist. I know this could have something to do with upper/lowercase, but because I need the .get(0) at the end of the statement, I don't know how I can fix this. Removing the .get(0) results in a return value list instead of an Ingredient, so I need this part.

但是,该列确实存在。我知道这可能与大写/小写有关,但因为我需要语句末尾的.get(0),我不知道如何解决这个问题。删除.get(0)会导致返回值列表而不是成分,所以我需要这部分。

Any ideas? Much appreciated.

有任何想法吗?非常感激。

public Ingredient findByString(String ingredientNaam) {
    return selectIngredients("SELECT * FROM ingredient WHERE ingredientnaam = "+ingredientNaam).get(0);
}

1 个解决方案

#1


2  

The ingredient is a string, so you need to quote it. If you don't, it is considered as a column name.

成分是一个字符串,所以你需要引用它。如果不这样做,则将其视为列名。

public Ingredient findByString(String ingredientNaam) {
    return selectIngredients("SELECT * FROM ingredient WHERE ingredientnaam = '"+ingredientNaam +"'").get(0);
}

#1


2  

The ingredient is a string, so you need to quote it. If you don't, it is considered as a column name.

成分是一个字符串,所以你需要引用它。如果不这样做,则将其视为列名。

public Ingredient findByString(String ingredientNaam) {
    return selectIngredients("SELECT * FROM ingredient WHERE ingredientnaam = '"+ingredientNaam +"'").get(0);
}