1.ResultSet目的:先判断rs是否为空,做出提示语,例如:“您的购物车空无一物”
[讨论参考](http://bbs.csdn.net/topics/60427882)
解决代码如下:
public void selectCart() throws SQLException{
Connection co=DBCP.getConnection();
String sql="select * from cart";
PreparedStatement ps=co.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
if(!rs.next()){System.out.println("购物车空无一物,请您先添加商品至购物车!");}
else{System.out.println("商品名称:"+rs.getString("goodsname")
+" 商品数量:"+rs.getInt("num")+" 商品单价:"+rs.getDouble("price"));}
while(rs.next()){
System.out.println("商品名称:"+rs.getString("goodsname")
+" 商品数量:"+rs.getInt("num")+" 商品单价:"+rs.getDouble("price"));
}
}