我试图在java中调试我准备好的语句,并且我坚持使用我实现的checkEmail
函数。当我进入调试并且它到达setString
行时,它显示NOT SPECIFIED而不是'?'
。如果我将'findEmail'
硬编码到String查询中,它将工作并找到该电子邮件。这是一段代码:
public static boolean checkEmail(String findEmail) {
Connection conn = EstablishConnection.conn;
boolean found = false;
try {
String query = "SELECT email FROM customers WHERE email=?";
Logging.debug(query);
PreparedStatement preparedStatement = conn.prepareStatement(query);
preparedStatement.setString(1,findEmail);
ResultSet rs = preparedStatement.executeQuery(query);
//Iterate through the results of the query
if (rs.next()) {
found = true;
}
preparedStatement.close();
} catch (Exception e) {
Logging.debug("Exception thrown in CustomerOperations.getCustomerInfo(): " + e.getMessage());
e.printStackTrace();
}
return found;
}
答案 0 :(得分:2)
尝试替换它:
ResultSet rs = preparedStatement.executeQuery(query);
使用:
ResultSet rs = preparedStatement.executeQuery();
因为您已将查询传递给prepareStatement
:conn.prepareStatement(query);