这个问题在这里已有答案:

当我尝试使用 jdbc 从我的数据库获取结果集时,我得到错误的语法错误,但我不知道为什么 .

String sq2 = ("SELECT id FROM player WHERE name = ? ");
 PreparedStatement st = con.prepareStatement(sq2);
 st.setString(1,name);
 ResultSet rs = st.executeQuery(sq2);

错误

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.StatementImpl.executeQuery(StatementImpl.java:1218)
at DataBase.InsertPlayer(DataBase.java:91)
at DataBase.main(DataBase.java:56)