我有一種方法,其返回類型是customer,它是pojo。當我從數據庫中獲得要求customerId
時,我想要返回客戶對象與相應的數據customerId
。這意味着它有客戶名稱,地址等。如何繼續?從數據庫中獲取數據並以pojo對象的形式返回
public class Customer verifyCustomerId(cutomerId){
statement = connection.createStatement();
resultSet = statement.executeQuery("select customerid from customer");
while (resultSet.next()) {
if (cutomerId == resultSet.getInt(1)) {
// return data corresponding to this id in the form of object of pojo customer
}
}
return null;
}
您是否在此邏輯開始時有customerId,還是您需要先找到它? – JamesB