gpt4 book ai didi

java - 错误 : SQLException: Parameter index out of range (1 > number of parameters, 为 0)

转载 作者:行者123 更新时间:2023-12-01 19:38:27 29 4
gpt4 key购买 nike

尽管上述准备好的语句的语法是正确的,但我收到以下错误:

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

预期结果是以下代码必须返回表的值

try{
conn = DatabaseMain.getConnection();
String instqury = "Select quality_name,quality_size,quality_weight,quality_spec from quality where quality_code = '?'";
pst1 = conn.prepareStatement(instqury);
pst1.setString(1, quality);

rs1 = pst1.executeQuery();
rs1.next();
name.setText(String.valueOf(rs1.getString("quality_name")));

}
catch(Exception e){
e.printStackTrace();
System.out.println("Error in setting labels for Machine View");
}

最佳答案

不要将占位符放在单引号之间:

String instqury = 
"Select quality_name,quality_size,quality_weight,quality_spec " +
"from quality where quality_code = ?";
^-- here

关于java - 错误 : SQLException: Parameter index out of range (1 > number of parameters, 为 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56520770/

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