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;
}
}
最近下载更多
青鸟飞雨 LV9
5月26日
微信网友_7043154826989568 LV1
2024年6月18日
Liang朝伟 LV1
2024年1月5日
xiongwei11231 LV9
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日

最近浏览
