java sql语法错误选择

java sql语法错误选择,java,sql,select,Java,Sql,Select,所以我有这个代码,它应该为我提供一行的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); Resu

所以我有这个代码,它应该为我提供一行的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(查询)
,只做
st.executeQuery()
不要做
st.executeQuery(查询)
,只做
st.executeQuery()
不要两次传递查询

   ResultSet rs = st.executeQuery(); 

不要将查询传入两次

   ResultSet rs = st.executeQuery(); 

只需使用
st.executeQuery()而不是
st.executeQuery(查询)


这里是只需使用
st.executeQuery()而不是
st.executeQuery(查询)


这是什么数据库?什么JDBC驱动程序?什么数据库?什么JDBC驱动程序?确实是这个问题。非常感谢您抽出时间。我是java sql的新手:)的确,这就是问题所在。非常感谢您抽出时间。我是java sql的新手:)