package cn.yizhi.dao;
import java.sql.*;
import java.util.*;
import cn.yizhi.bean.*;
public class GoodsDao {
private Connection con = null;
private Statement stmt = null;
private PreparedStatement pstmt = null;
private ResultSet rs = null;
/*
* 添加商品
*/
public boolean insert(Goods gs) {
boolean isSucc = false;
String sql = "insert into goods values(?,?,?,?,?,?,?,?,default,?,?)";
try {
con = DBConn.getConn();
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, gs.getCategoryIdfirst());
pstmt.setInt(2, gs.getCategoryIdsecond());
pstmt.setInt(3, gs.getCategoryIdthird());
pstmt.setString(4, gs.getGoodsName());
pstmt.setFloat(5, gs.getPrice());
pstmt.setInt(6, gs.getIsCommd());
pstmt.setFloat(7, gs.getSalePrice());
pstmt.setString(8, gs.getDescriptions());
pstmt.setInt(9, gs.getIsExist());
pstmt.setInt(10, gs.getSaleTotal());
int count = pstmt.executeUpdate();
if(count > 0) {
isSucc = true;
}
} catch (SQLException se) {
se.printStackTrace();
} finally {
try {
pstmt.close();
con.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return isSucc;
}
/*
* 删除商品
*/
public boolean delete(Goods gs) {
boolean isSucc = false;
int id = gs.getGoodsId();
String sql = "delete from orderDetail where goodsId="+id;
String sql1 = "delete from goods where goodsId="+id;
try {
con = DBConn.getConn();
con.setAutoCommit(false);
stmt = con.createStatement();
stmt.executeUpdate(sql);
int count = stmt.executeUpdate(sql1);
con.commit();
if(count > 0) {
isSucc = true;
}
} catch (SQLException se) {
try {
con.rollback();
}catch(Exception e) {
}
se.printStackTrace();
} finally {
try {
stmt.close();
con.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return isSucc;
}
/*
* 更新商品
*/
public boolean update(Goods gs) {
boolean isSucc = false;
String sql = "update goods set categoryIdfirst=?,categoryIdsecond=?," +
"categoryIdthird=?,goodsName=?,price=?,isCommd=?,salePrice=?," +
"descriptions=?,isExist=?,saleTotal=? where goodsId=?";
try {
con = DBConn.getConn();
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, gs.getCategoryIdfirst());
pstmt.setInt(2, gs.getCategoryIdsecond());
pstmt.setInt(3, gs.getCategoryIdthird());
pstmt.setString(4, gs.getGoodsName());
pstmt.setFloat(5, gs.getPrice());
pstmt.setInt(6, gs.getIsCommd());
pstmt.setFloat(7, gs.getSalePrice());
pstmt.setString(8, gs.getDescriptions());
pstmt.setInt(9, gs.getIsExist());
pstmt.setInt(10, gs.getSaleTotal());
pstmt.setInt(11, gs.getGoodsId());
int count = pstmt.executeUpdate();
if(count > 0) {
isSucc = true;
}
} catch (SQLException se) {
se.printStackTrace();
} finally {
try {
pstmt.close();
con.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return isSucc;
}
/*
* 更新点击率
*/
public boolean update1(Goods gs) {
boolean isSucc = false;
String sql = "update goods set saleCount=? where goodsId=?";
try {
con = DBConn.getConn();
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, gs.getSaleCount());
pstmt.setInt(2, gs.getGoodsId());
int count = pstmt.executeUpdate();
if(count > 0) {
isSucc = true;
}
} catch (SQLException se) {
se.printStackTrace();
} finally {
try {
pstmt.close();
con.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return isSucc;
}
/*
* 更新库存
*/
public boolean update2(Goods gs) {
boolean isSucc = false;
String sql = "update goods set saleTotal=? where goodsId=?";
try {
con = DBConn.getConn();
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, gs.getSaleTotal());
pstmt.setInt(2, gs.getGoodsId());
int count = pstmt.executeUpdate();
if(count > 0) {
isSucc = true;
}
} catch (SQLException se) {
se.printStackTrace();
} finally {
try {
pstmt.close();
con.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return isSucc;
}
/*
* 更新商品状态,是否有货
*/
public boolean update3(Goods gs) {
boolean isSucc = false;
String sql = "update goods set isExist=? where goodsId=?";
try {
con = DBConn.getConn();
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, gs.getIsExist());
pstmt.setInt(2, gs.getGoodsId());
int count = pstmt.executeUpdate();
if(count > 0) {
isSucc = true;
}
} catch (SQLException se) {
se.printStackTrace();
} finally {
try {
pstmt.close();
con.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return isSucc;
}
/*
* 查询所有商品
*/
public List getCategorys(PageDiv pd) {
int requestPage = pd.getRequestPage();
pd.setCurrPage(requestPage);
String tabName = pd.getTabName();
int requestRecord = (requestPage - 1) * 10;
List list = new ArrayList();
String sql = "select top 10 * from " + tabName
+ " where goodsId " + "not in(select top "
+ requestRecord + " goodsId from " + tabName + " order by saleCount desc) " +
"order by saleCount desc";
try {
con = DBConn.getConn();
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
Goods gs = new Goods();
gs.setGoodsId(rs.getInt("goodsId"));
gs.setGoodsName(rs.getString("goodsName"));
gs.setPrice(rs.getFloat("price"));
gs.setSalePrice(rs.getFloat("salePrice"));
gs.setDescriptions(rs.getString("descriptions"));
gs.setSaleCount(rs.getInt("saleCount"));
gs.setIsExist(rs.getInt("isExist"));
list.add(gs);
}
} catch (SQLException se) {
se.printStackTrace();
} finally {
try {
rs.close();
stmt.close();
con.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return list;
}
/*
* 根据ID查询
*/
public List getGoods(Goods gs) {
List list = new ArrayList();
String sql = "select * from goods where 1=1";
try {
con = DBConn.getConn();
pstmt = con.prepareStatement(sql);
if(gs.getGoodsId() != 0) {
sql = sql + " and goodsId=?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, gs.getGoodsId());
}
if(gs.getCategoryIdfirst() != 0 && gs.getCategoryIdsecond() != 0 && gs.getCategoryIdthird() != 0) {
sql = sql + " and categoryIdfirst=? and categoryIdsecond=? and categoryIdthird=?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, gs.getCategoryIdfirst());
pstmt.setInt(2, gs.getCategoryIdsecond());
pstmt.setInt(3, gs.getCategoryIdthird());
}
rs = pstmt.executeQuery();
while (rs.next()) {
gs = new Goods();
gs.setGoodsId(rs.getInt("goodsId"));
gs.setGoodsName(rs.getString("goodsName"));
gs.setPrice(rs.getFloat("price"));
gs.setSalePrice(rs.getFloat("salePrice"));
gs.setDescriptions(rs.getString("descriptions"));
gs.setSaleCount(rs.getInt("saleCount"));
gs.setIsExist(rs.getInt("isExist"));
gs.setSaleTotal(rs.getInt("saleTotal"));
list.add(gs);
}
} catch (SQLException se) {
se.printStackTrace();
} finally {
try {
rs.close();
pstmt.close();
con.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
return list;
}
/*
* 商品模糊查询
*/
public List goodsLike(Goods gs) {
List list = new ArrayList();
String sql = "select * from goods where goodsName like ?";
try {
con = DBConn.getConn();
pstmt = con.prepareStatement(sql);
String name = "%"+gs.getGoodsName()+"%";
pstmt.setString(1, name);
rs = pstmt.executeQuery();
while (rs.next()) {
gs = new Goods();
gs.
没有合适的资源?快使用搜索试试~ 我知道了~
超市购物管理系统 (JAVA)
共92个文件
java:33个
class:33个
jsp:16个
需积分: 34 16 下载量 105 浏览量
2008-09-12
20:06:39
上传
评论 2
收藏 474KB RAR 举报
温馨提示
用 MyEclipse 编写 不需要人和插件就可以运行
资源推荐
资源详情
资源评论
收起资源包目录
Shopping.rar (92个子文件)
Shopping
src
cn
yizhi
filter
LoginFilter1.java 961B
LoginFilter.java 941B
ValidateFilter.java 1KB
dao
GoodsDao.java 10KB
CategoryThirdDao.java 3KB
CategoryDao.java 324B
DBConn.java 559B
impl
UserDaoImpl.java 3KB
CategoryDaoImpl.java 3KB
ShoppingCartDao.java 4KB
OrdersDao.java 5KB
OrderDetailDao.java 3KB
CategorySecondDao.java 3KB
UserDao.java 220B
bean
CategorySecond.java 911B
ShoppingCart.java 1KB
OrderDetail.java 696B
Users.java 2KB
PageDiv.java 2KB
OrderGoods.java 58B
Orders.java 2KB
Goods.java 4KB
Category.java 686B
CategoryThird.java 1KB
service
CategoryService.java 312B
UserService.java 225B
impl
UserServiceImpl.java 439B
CategoryServiceImpl.java 612B
servlet
GoodsServlet.java 7KB
SubmitOrderServlet.java 6KB
UserServlet.java 5KB
ShoppingServlet.java 3KB
OrderManServlet.java 4KB
.classpath 574B
.mymetadata 297B
.settings
org.eclipse.jdt.core.prefs 330B
.myeclipse
.project 1KB
WebRoot
META-INF
MANIFEST.MF 39B
login
errorLogin.jsp 242B
goodsQuery.jsp 6KB
goodsList.jsp 2KB
errorRegister.jsp 219B
login.jsp 2KB
indexShopping.jsp 6KB
register.jsp 5KB
index.jsp 799B
css
styles.css 760B
shop
displayInfo.jsp 2KB
userOrder.jsp 3KB
shoppingCart.jsp 3KB
userInfo.jsp 2KB
category
addCategory.jsp 12KB
error.jsp 799B
adminIndex.jsp 5KB
updateGoods.jsp 6KB
WEB-INF
classes
cn
yizhi
filter
LoginFilter.class 2KB
LoginFilter1.class 2KB
ValidateFilter.class 2KB
dao
OrdersDao.class 5KB
GoodsDao.class 10KB
OrderDetailDao.class 4KB
impl
CategoryDaoImpl.class 3KB
UserDaoImpl.class 4KB
CategoryDao.class 357B
CategoryThirdDao.class 3KB
CategorySecondDao.class 4KB
UserDao.class 257B
DBConn.class 1KB
ShoppingCartDao.class 5KB
bean
PageDiv.class 2KB
OrderGoods.class 283B
CategoryThird.class 1KB
ShoppingCart.class 2KB
Category.class 1004B
CategorySecond.class 1KB
Orders.class 2KB
Goods.class 5KB
Users.class 2KB
OrderDetail.class 1KB
service
UserService.class 242B
impl
UserServiceImpl.class 858B
CategoryServiceImpl.class 1KB
CategoryService.class 319B
servlet
OrderManServlet.class 3KB
GoodsServlet.class 5KB
UserServlet.class 4KB
SubmitOrderServlet.class 5KB
ShoppingServlet.class 4KB
lib
msbase.jar 295KB
mssqlserver.jar 68KB
msutil.jar 66KB
web.xml 3KB
共 92 条
- 1
资源评论
xuwei06121012
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功