📄 goodsdao.java~3~
字号:
package com.dao;
import java.sql.*;
import java.util.*;
import com.tool.JDBConnection;
import com.tool.FinalConstants;
import com.domain.GoodsForm;
//对商品表的操作
public class GoodsDao {
private Connection connection = null; //定义连接的对象
private PreparedStatement ps = null; //定义预准备的对象
private JDBConnection jdbc = null; //定义数据库连接对象
public GoodsDao() {
jdbc = new JDBConnection();
connection = jdbc.connection; //利用构造方法取得数据库连接
}
//添加操作
public void insertGoods(GoodsForm form) {
try {
ps = connection.prepareStatement(FinalConstants.goods_insert);
ps.setInt(1, form.getBig().intValue());
ps.setInt(2, form.getSmall().intValue());
ps.setString(3, form.getName());
ps.setString(4, form.getFrom());
ps.setString(5, form.getIntroduce());
ps.setString(6, form.getCreaTime());
ps.setFloat(7, form.getNowPrice().floatValue());
ps.setFloat(8, form.getFreePrice().floatValue());
ps.setInt(9, form.getNumber().intValue());
ps.executeUpdate();
ps.close();
//insert into tb_goods values (?,?,?,?,?,getDate(),?,?,?)
}
catch (SQLException ex) {
}
}
//以商品编号为条件删除信息
public void deleteGoods(Integer id) {
try {
ps = connection.prepareStatement(FinalConstants.goods_delete);
ps.setInt(1, id.intValue());
ps.executeUpdate();
ps.close();
}
catch (SQLException ex) {
}
}
//以商品的编号为条件查询信息
public GoodsForm selectOneGoods(Integer id) {
GoodsForm goods = null;
try {
ps = connection.prepareStatement(FinalConstants.goods_selectOne);
ps.setInt(1, id.intValue());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
goods = new GoodsForm();
goods.setId(Integer.valueOf(rs.getString(1)));
goods.setBig(Integer.valueOf(rs.getString(2)));
goods.setSmall(Integer.valueOf(rs.getString(3)));
goods.setName(rs.getString(4));
goods.setFrom(rs.getString(5));
goods.setIntroduce(rs.getString(6));
goods.setCreaTime(rs.getString(7));
goods.setNowPrice(Float.valueOf(rs.getString(8)));
goods.setFreePrice(Float.valueOf(rs.getString(9)));
goods.setNumber(Integer.valueOf(rs.getString(10)));
}
}
catch (SQLException ex) {
}
return goods;
}
//以商品的小类别的编号为条件查询信息
public List selectSmall(Integer small) {
List list = new ArrayList();
GoodsForm goods = null;
try {
ps = connection.prepareStatement(FinalConstants.goods_selectSmall);
ps.setInt(1, small.intValue());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
goods = new GoodsForm();
goods.setId(Integer.valueOf(rs.getString(1)));
goods.setBig(Integer.valueOf(rs.getString(2)));
goods.setSmall(Integer.valueOf(rs.getString(3)));
goods.setName(rs.getString(4));
goods.setFrom(rs.getString(5));
goods.setIntroduce(rs.getString(6));
goods.setCreaTime(rs.getString(7));
goods.setNowPrice(Float.valueOf(rs.getString(8)));
goods.setFreePrice(Float.valueOf(rs.getString(9)));
goods.setNumber(Integer.valueOf(rs.getString(10)));
list.add(goods);
}
}
catch (SQLException ex) {
}
return list;
}
//以商品的大类别的编号为条件查询信息
public List selectBig(Integer big) {
List list = new ArrayList();
GoodsForm goods = null;
try {
ps = connection.prepareStatement(FinalConstants.goods_selectBig);
ps.setInt(1, big.intValue());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
goods = new GoodsForm();
goods.setId(Integer.valueOf(rs.getString(1)));
goods.setBig(Integer.valueOf(rs.getString(2)));
goods.setSmall(Integer.valueOf(rs.getString(3)));
goods.setName(rs.getString(4));
goods.setFrom(rs.getString(5));
goods.setIntroduce(rs.getString(6));
goods.setCreaTime(rs.getString(7));
goods.setNowPrice(Float.valueOf(rs.getString(8)));
goods.setFreePrice(Float.valueOf(rs.getString(9)));
goods.setNumber(Integer.valueOf(rs.getString(10)));
list.add(goods);
}
}
catch (SQLException ex) {
}
return list;
}
//全部查询
public List selectGoods() {
List list = new ArrayList();
GoodsForm goods = null;
try {
ps = connection.prepareStatement(FinalConstants.goods_select);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
goods = new GoodsForm();
goods.setId(Integer.valueOf(rs.getString(1)));
goods.setBig(Integer.valueOf(rs.getString(2)));
goods.setSmall(Integer.valueOf(rs.getString(3)));
goods.setName(rs.getString(4));
goods.setFrom(rs.getString(5));
goods.setIntroduce(rs.getString(6));
goods.setCreaTime(rs.getString(7));
goods.setNowPrice(Float.valueOf(rs.getString(8)));
goods.setFreePrice(Float.valueOf(rs.getString(9)));
goods.setNumber(Integer.valueOf(rs.getString(10)));
list.add(goods);
}
}
catch (SQLException ex) {
}
return list;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -