gpt4 book ai didi

java.sql.SQLException : Parameter index out of range (1 > number of parameters, 为 0)。使用 PreparedStatement 时

转载 作者:搜寻专家 更新时间:2023-10-31 20:12:12 25 4
gpt4 key购买 nike

<分区>

在 Java/MariaDb 中使用 preparedStatement 如下函数

public ArrayList<String> findPath(String roomName) throws SQLException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException
{
ArrayList<String> path = new ArrayList<String>();
connection = getConnection();
String queryPattern = "SELECT `Livello_1`, `Livello_2`, `Livello_3`, `Livello_4` FROM Camera WHERE Camera.Nome = '?'";
PreparedStatement queryStatement = connection.prepareStatement(queryPattern);
queryStatement.setString(1, roomName);
ResultSet rs = queryStatement.executeQuery();
if(rs.next())
{
for(int i = 0; i < 3; i++)
{
path.add(rs.getString(i));
}
}
return path;
}

我收到错误信息:

java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

错误行号指向行

queryStatement.setString(1, roomName);

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com