1
收到密碼,我得到一個錯誤,在這種方法時:準備語句錯誤試圖從DB
public String databaseServer(String email)throws IllegalArgumentException {
Connection dbCon = null;
Statement stmt = null;
String password = null;
System.out.print(email);
String query = "SELECT password FROM user WHERE email = ?";
try{
dbCon = initializeDBConnection();
PreparedStatement preparedStatement = dbCon.prepareStatement(query);
preparedStatement.setString(1, email);
ResultSet rs = preparedStatement.executeQuery(query);
while (rs.next()) {
password = rs.getString("password");
}
} catch (SQLException ex) {
Logger.getLogger(Collection.class.getName()).log(Level.SEVERE, null, ex);
}
//close connection ,stmt and resultset here
return password;
}
的錯誤是: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
我檢查連接和輸入字符串,他們都工作正常。
有人知道我在做什麼錯嗎?取而代之的
ResultSet rs = preparedStatement.executeQuery(query);
謝謝你的好先生! (我將在11分鐘內將答案標記爲正確) – Mangs