我對基於ResultSet
創建的對象有疑問。基於結果集創建對象
比方說,我有一個產品DAO類:
public class ProductDAO
{
...
ResultSet products = statement.executeQuery("SELECT * FROM PRODUCT ");
if (products .next()) {
int prodId = products .getInt("id");
String prodName = products .getString("name");
Product product = new Product(prodId, prodName);
}
...
}
比方說,SQL查詢返回5行。結果,產品對象最終會包含什麼?它是否只包含最終返回行的值(在本例中是第5行)?
然後用'while'循環('而( products.next())')將數據庫中的數據檢索到對象中。 – 2014-10-30 07:56:49