gpt4 book ai didi

java sql语法错误选择

转载 作者:行者123 更新时间:2023-12-01 17:31:14 26 4
gpt4 key购买 nike

所以我有这段代码,它应该为我提供行的 id。

public int getIdSala(Connection conn, String t) {
try {
String query = "Select id_sala from sala where nume = ?";

PreparedStatement st = conn.prepareStatement(query);
st.setString(1, t);
ResultSet rs = st.executeQuery(query);

id = rs.getInt("Id_sala");

} catch (Exception e) {
System.err.println("Got an exception!");
System.err.println(e.getMessage());
}
return id;
}

我收到以下错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQLserver version for the right syntax to use near '?' at line 1

可能是什么问题?

最佳答案

不要执行st.executeQuery(query),而只执行st.executeQuery()

关于java sql语法错误选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10667517/

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