当我尝试使用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)