You will have to remove the query
argument from your executeQuery
call. If you provide the parameter, the query will be executed without binding any values (see Statement for details) - this is why the syntax (i.e. the ?
) is invalid.
Execute the query like this:
ResultSet rst = st.executeQuery();
As a side note: you should always wrap Connection
, PreparedStatement
and ResultSet
with a try-with-resources block, e.g.
try (ResultSet rst = st.executeQuery()) {
// read the results
}
This way you can be sure the ResultSet
will be closed no matter what happens.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…