sql的简单增删改查
来源:互联网 发布:阿里云cdn combo 编辑:程序博客网 时间:2024/06/06 02:44
package DAO;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import entity.product;public class zengshangaicha extends jidao{public void add(product pp){StringBuilder sql=new StringBuilder("insert into product(pid,pname,pprice,plei,pdate) ");sql.append("values(?,?,?,?,?)");String execSql = sql.toString();java.sql.Date bornDate = new java.sql.Date(pp.getDate().getTime());Object[] list={pp.getId(),pp.getName(),pp.getPrice(),pp.getPlei(),bornDate};super.execUpdate(execSql, list);}public List<product> getall(){String sql="select * from product";ResultSet rs=super.execQuery(sql, null);List<product> list=new ArrayList<product>();try {while(rs.next()){product pp1=new product();pp1.setId(rs.getInt("pid"));pp1.setName(rs.getString("pname"));pp1.setPrice(rs.getFloat("pprice"));pp1.setPlei(rs.getString("plei"));pp1.setDate(rs.getDate("pdate"));list.add(pp1);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return list;}public void del(int id){String sql="delete from product where pid=? ";super.execUpdate(sql, new Object[]{id});}public List<product> findbyid(int id){String sql="select * from product where pid=? ";ResultSet rs=super.execQuery(sql, new Object[]{id});List<product> list=new ArrayList<product>();try {if(rs.next()){product pp1=new product();pp1.setId(rs.getInt("pid"));pp1.setName(rs.getString("pname"));pp1.setPrice(rs.getFloat("pprice"));pp1.setPlei(rs.getString("plei"));pp1.setDate(rs.getDate("pdate"));list.add(pp1);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return list;}public void update(product pp2){String sql="update product set pname=?,pprice=?,plei=?,pdate=? where pid=? ";java.sql.Date date1 = new java.sql.Date(pp2.getDate().getTime());Object[] oo={pp2.getName(),pp2.getPrice(),pp2.getPlei(),pp2.getDate(),pp2.getId()};super.execUpdate(sql, oo);}}
0 0
- sql的简单的增删改查
- sql的简单增删改查
- SQL语言简单的增删改查
- SQL --最简单的增删改查
- sql的增删改查
- SQL的增删改查
- Java、SQL Serve ----简单的增删查改
- sql增删改查之简单查询
- SQL增删改查
- sql 增删改查
- SQL增删改查
- SQL增删改查
- SQL---增删改查
- sql增删改查
- sql增删改查
- Dom4j的增删改查简单使用
- Extjs tree 的简单增删改查
- Hibernate 简单的增删改查 示例
- 归并排序求逆序数——HDU 4911
- 华为OJ训练题之 比赛情况统计
- I am a newcomer
- apt软件包管理
- Mongodb 之insert瞬时完成,带测试数据---飞天博客
- sql的简单增删改查
- IOS开发系列--Objective-C之KVC、KVO
- 深刻理解Linux进程间通信(IPC)
- js获取非行间样式
- Android之fragment初探
- 最简单的实体类
- minGW的简单使用
- vfrt砸死蓄电池而对非常vgb
- iOS中assign、copy 、retain等关键字的含义