-3
public Customer getCustomer(String ssNum) throws CustomerHomeException, ClassNotFoundException {
  String query = "Select ssn, customer_name from customer ";
  ResultSet rs = smt.executeQuery(query);
  Customer customer = null;
  while (rs.next()) {
    if (ssNum.equals(rs.getString("ssn"))) {
      customer = new Customer(rs.getString("ssn"), rs.getString("customer_name"));
    }
    return customer;
  }
  } catch (SQLException e) {
    throw new CustomerHomeException("Failed to create CustomerHome", e);
  }
}

从MySQL数据库中return检索值时放置的语句出现错误。值已经存在。

4

1 回答 1

0

getCustomer期望return customer在函数定义末尾的方法。并且您正在while循环中间返回。所以编译器抱怨添加或放置 return 语句作为你的方法假设,因为它并不总是发生whileif每次都会被执行。

private static int hello() {
    for (int i = 0; i < 2; i++) {
        return 0;
    }
    return -1;
}

我希望这有帮助。

于 2013-05-14T21:11:29.860 回答