【发布时间】:2016-05-27 20:50:19
【问题描述】:
我正在尝试在 java 中调试我准备好的语句,但我被困在我实现的这个 checkEmail 函数上。当我进入调试并到达setString 行时,它显示未指定代替'?'。如果我将'findEmail' 硬编码到字符串查询中,它将起作用并找到电子邮件。这是一段代码:
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;
}
【问题讨论】:
-
你需要
ResultSet rs = preparedStatement.executeQuery(); -
该死的,我认为这很简单。谢谢!