gpt4 book ai didi

java - 我的 JDBC select 准备语句有什么问题?

转载 作者:行者123 更新时间:2023-11-30 03:03:05 26 4
gpt4 key购买 nike

我正在尝试在 java 中调试我准备好的语句,但我陷入了这个 checkEmail我实现的功能。当我进入调试状态时,它达到 setString行,它显示 NOT SPECIFIED 代替 '?' 。如果我硬编码'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(query);

与:

  ResultSet rs = preparedStatement.executeQuery();

因为您已经将查询传递给 prepareStatement :conn.prepareStatement(query);

关于java - 我的 JDBC select 准备语句有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35434865/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com