package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import util.DBUtil;
import entity.Computer;

public class ComputerDAO {
	public List<Computer> findAll()throws Exception{
		List<Computer> computers = new ArrayList<Computer>();
		Connection conn = DBUtil.getConnection();
		PreparedStatement prep = conn.prepareStatement("select*from t_computer");
		ResultSet rst = prep.executeQuery();
		while(rst.next()){
			Computer c = new Computer();
			c.setId(rst.getLong("id"));
			c.setModel(rst.getString("model"));
			c.setPicName(rst.getString("picName"));
			c.setPrice(rst.getDouble("price"));
			c.setProdDesc(rst.getString("prodDesc"));
			computers.add(c);
		}
		DBUtil.close(conn);
		return computers;
	}
	public Computer findById(long id)throws Exception{
		Computer c = null;
		Connection conn = DBUtil.getConnection();
		PreparedStatement prep = conn.prepareStatement("select*from t_computer where id=?");
		prep.setLong(1, id);
		ResultSet rst = prep.executeQuery();
		if(rst.next()){
			c = new Computer();
			c.setId(rst.getLong("id"));
			c.setModel(rst.getString("model"));
			c.setPicName(rst.getString("picName"));
			c.setPrice(rst.getDouble("price"));
			c.setProdDesc(rst.getString("prodDesc"));
		}
		DBUtil.close(conn);
		return c;
	}
}









最近下载更多
Liang朝伟  LV1 1月5日
xiongwei11231  LV8 2023年12月2日
xiaotang156  LV2 2023年11月25日
才旬空  LV2 2023年11月11日
2036495585  LV9 2023年9月25日
win_or_gohome  LV1 2023年4月22日
mylzdy  LV12 2023年4月10日
17714813570  LV2 2022年12月22日
微信网友_6190641661054976  LV2 2022年10月27日
13112360  LV2 2022年9月27日
最近浏览更多
taoshen95  LV14 3月22日
阿猫喵喵喵996  LV12 1月25日
Liang朝伟  LV1 1月5日
asddwh  LV12 2023年12月25日
pangzhihui  LV12 2023年12月23日
yuanshun  LV6 2023年12月22日
李朝磊  LV18 2023年12月21日
颜菜菜  LV2 2023年12月19日
dai呆代  LV1 2023年12月3日
xiongwei11231  LV8 2023年12月2日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友