gpt4 book ai didi

java - java中的mysql选择查询

转载 作者:行者123 更新时间:2023-11-29 03:58:41 24 4
gpt4 key购买 nike

我刚开始接触 java 和 mysql 数据库。我的查询有什么问题:

PreparedStatement statement = conn.prepareStatement("SELECT * FROM q_table, choices, answers  WHERE q_table.QID='" + number_input + "' AND choices.CID='" + number_input + "' AND answers.AID='" + number_input + "'");

最佳答案

在您的语句 "... q_table.QID='"+ number_input + "' AND ... 中,变量 number_input 包含在单引号 (' ). 这用于 string lieterals . 如果你删除单引号它应该工作:

 String prest= "SELECT * FROM q_table, choices, answers  WHERE questions.QID=? AND choices.CID=? AND answers.AID=?";

prest.setInt(1,1980);
prest.setInt(2,2004);
.
.
ResultSet rs = prest.executeQuery();
while (rs.next()){
String mov_name = rs.getString(1);
int mov_year = rs.getInt(2);
count++;
System.out.println(mov_name + "\t" + "- " + mov_year);
}
System.out.println("Number of records: " + count);
prest.close();
con.close();

关于java - java中的mysql选择查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5089229/

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