我有一个preparedStatement,用于mySQL中的select查询。
我就是这么写的:
String sQuery = "SELECT Password FROM test WHERE Email = ?";
st = DB.prepareStatement(sQuery);
st.setString(1, email);
ResultSet rs = st.executeQuery(sQuery);
但我从玻璃鱼服务器上得到了一个例外,它说:
Severe: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '?' at line 1
我不明白有什么问题..。我看到的所有样本都用那个语法..。
发布于 2014-08-19 19:27:49
您必须调用st.executeQuery()
,而不使用查询作为参数。在准备语句时,查询已经传递给语句。
请参阅http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html#executeQuery%28%29
发布于 2014-08-19 19:28:55
st.executeQuery()
,即no param to executeQuery
https://stackoverflow.com/questions/25391409
复制相似问题