package com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import com.entity.CommentInfo;
import com.entity.GoodsInfo;
/**
* 商品操作类
* @author Administrator
*
*/
public class GoodsCtrl {
/**
* 添加商品方法
* @param goods
* @return
*/
public int addGoods(GoodsInfo goods){
int res =0;
Connection conn =ConnDB.getConn();
PreparedStatement stmt =null;
String sql ="insert into GoodsInfo values(?,?,?,?,?,?,?,?,?,?,?,?)";
try {
stmt =conn.prepareStatement(sql);
stmt.setString(1, goods.getGoodsname());
stmt.setString(2, goods.getGoodssort());
stmt.setDouble(3, goods.getGoodsprice());
stmt.setDouble(4, goods.getGoodscarr());
stmt.setString(5, goods.getGoodsaddr());
stmt.setString(6, goods.getGoodsimg());
stmt.setString(7, goods.getGoodstuijian());
stmt.setString(8, goods.getGoodsxianliang());
stmt.setString(9, goods.getGoodstejia());
stmt.setString(10, goods.getGoodscuxiao());
stmt.setString(11, goods.getGoodszt());
stmt.setString(12, goods.getGoodsintro());
res =stmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnDB.close(null, stmt, conn);
}
return res;
}
/*==商品列表数据分页==*/
/**
* 根据当前页数和每页显示的行数来查询相应的结果
*
* @param pageSize
* 每页显示的行数
* @param pageNow
* 当前的页数
* @return
*/
public ArrayList<GoodsInfo> getGoodsForPage(int pageSize, int pageNow) {
ArrayList<GoodsInfo> agoods = null;
Connection conn = ConnDB.getConn();
Statement stmt = null;
ResultSet rs = null;
String sql = "select Top " + pageSize
+ " * from GoodsInfo where goodsId not in(select Top (" + pageSize
+ " * (" + pageNow + "- 1)) goodsId from GoodsInfo)";
try {
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
while(rs.next()){
if(agoods==null){
agoods=new ArrayList<GoodsInfo>();
}
GoodsInfo goods = new GoodsInfo();
goods.setGoodsId(rs.getInt("goodsId"));
goods.setGoodsname(rs.getString("goodsName"));
goods.setGoodssort(rs.getString("goodsSort"));
goods.setGoodsprice(rs.getDouble("goodsPrice"));
goods.setGoodscarr(rs.getDouble("goodsCarr"));
goods.setGoodsaddr(rs.getString("goodsAddr"));
goods.setGoodsimg(rs.getString("goodsImg"));
goods.setGoodszt(rs.getString("goodsZt"));
agoods.add(goods);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnDB.close(rs, stmt, conn);
}
return agoods;
}
/**
* 获取总页数
* @param pageSize
* @return
*/
public int getGoodsCount(int pageSize){
int pageCount = 0;
int goodsCount = 0;//获取到商品的总数
Connection conn = ConnDB.getConn();
Statement stmt = null;
ResultSet rs = null;
String sql = "select count(*) as goodsCount from GoodsInfo";
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if(rs.next()){
goodsCount = rs.getInt("goodsCount");
}
//页数计算
if(goodsCount % pageSize == 0){
pageCount = goodsCount / pageSize;
}else{
pageCount = goodsCount / pageSize + 1;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnDB.close(rs, stmt, conn);
}
return pageCount;
}
/**
* 根据ID查询商品方法
* @param goodsId
* @return
*/
public GoodsInfo selgoods(int goodsId){
GoodsInfo goods = null;
Connection conn = ConnDB.getConn();
Statement stmt = null;
ResultSet rs = null;
String sql = "select * from GoodsInfo where goodsId=" + goodsId;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if(rs.next()){
goods = new GoodsInfo();
goods.setGoodsId(rs.getInt("goodsId"));
goods.setGoodsname(rs.getString("goodsName"));
goods.setGoodssort(rs.getString("goodsSort"));
goods.setGoodsprice(rs.getDouble("goodsPrice"));
goods.setGoodscarr(rs.getDouble("goodsCarr"));
goods.setGoodsaddr(rs.getString("goodsAddr"));
goods.setGoodsimg(rs.getString("goodsImg"));
goods.setGoodstuijian(rs.getString("goodsTuijian"));
goods.setGoodsxianliang(rs.getString("goodsXianliang"));
goods.setGoodstejia(rs.getString("goodsTejia"));
goods.setGoodscuxiao(rs.getString("goodsCuxiao"));
goods.setGoodszt(rs.getString("goodsZt"));
goods.setGoodsintro(rs.getString("goodsIntro"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnDB.close(rs, stmt, conn);
}
return goods;
}
/**
* 修改商品方法
*/
public int updateGoods(GoodsInfo goods){
int res = 0;
Connection conn =ConnDB.getConn();
PreparedStatement stmt = null;
String sql = "update GoodsInfo set goodsName=?,goodsSort=?,goodsPrice=?,goodsCarr=?,goodsAddr=?,goodsImg=?,goodsTuijian=?,goodsXianliang=?,goodsTejia=?,goodsCuxiao=?,goodsZt=?,goodsIntro=?" +" where goodsId=?";
try {
stmt =conn.prepareStatement(sql);
stmt.setString(1, goods.getGoodsname());
stmt.setString(2, goods.getGoodssort());
stmt.setDouble(3, goods.getGoodsprice());
stmt.setDouble(4, goods.getGoodscarr());
stmt.setString(5, goods.getGoodsaddr());
stmt.setString(6, goods.getGoodsimg());
stmt.setString(7, goods.getGoodstuijian());
stmt.setString(8, goods.getGoodsxianliang());
stmt.setString(9, goods.getGoodstejia());
stmt.setString(10, goods.getGoodscuxiao());
stmt.setString(11, goods.getGoodszt());
stmt.setString(12, goods.getGoodsintro());
stmt.setInt(13, goods.getGoodsId());
res = stmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnDB.close(null, stmt, conn);
}
return res;
}
/**
* 根据ID删除商品
* @param userId
* @return
*/
public int deleteGoods(int goodsId){
int res = 0;
String sql = "delete GoodsInfo where goodsId=?";
Connection conn = ConnDB.getConn();
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement(sql);
stmt.setInt(1, goodsId);
res = stmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnDB.close(null, stmt, conn);
}
return res;
}
/*==推荐、限量、特价、促销商品搜索数据分页==*/
/**
* 根据导航栏连接搜索商品 *
* 根据当前页数和每页显示的行数来查询相应的结果
*
* @param pageSize
* 每页显示的行数
* @param pageNow
* 当前的页数
* @param tj
* 查询条件:(推荐、特价等)
* @return
*/
public ArrayList<GoodsInfo> getDaohlGoods(int pageSize, int pageNow,String tj) {
ArrayList<GoodsInfo> agoods = null;
Connection conn = ConnDB.getConn();
Statement stmt = null;
ResultSet rs = null;
String sql = "select Top " + pageSize
+ " * from GoodsInfo where goodsId not in(select Top (" + pageSize
+ " * (" + pageNow + "- 1)) goodsId from GoodsInfo) and "+tj+"='true' and goodsZt='true' order by goodsId desc";
try {
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
while(rs.next()){
if(agoods==null){
agoods=new ArrayList<GoodsInfo>();
}
GoodsInfo goods = new GoodsInfo();
goods.setGoodsId(rs.getInt("goodsId"));
goods.setGoodsname(rs.getString("goodsName"));
goods.setGoodsprice(rs.getDouble("goodsPrice"));
goods.setGoodsimg(rs.getString("goodsImg"));
agoods.add(goods);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnDB.close(rs, stmt
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源概述: 此资源集包含了一套完整的Java实现的购物商城项目源代码、相关的毕业论文以及详尽的使用说明。它旨在提供一个全面、深入的学习和研究工具,适用于本科课程设计、毕业设计以及任何希望深入学习Java编程的学习者。 详细内容: 源代码——提供了一套完整、经过良好注释的Java源代码,实现了购物商城项目的全部功能。代码结构清晰,逻辑严谨,是学习Java编程和项目实践的优秀材料。 毕业论文——包含了一篇探讨购物商城项目背景、技术原理和实现过程的学术论文,可作为论文撰写参考。通过阅读论文,学习者可以了解项目的理论基础,深入理解项目的实现细节,提升分析和解决问题的能力。 使用说明——详细的使用说明文档帮助学习者快速了解项目结构和使用方法,降低学习难度,提高学习效率。 适用对象: 此资源集适用于计算机科学、软件工程等专业的本科生进行课程设计和毕业设计。同时,对于希望提升Java编程技能、了解项目实践过程的学习者,这也是一份不可多得的学习资料。
资源推荐
资源详情
资源评论
收起资源包目录
Java实现的购物商城,可用作毕业设计,课程设计 (318个子文件)
yzm1.bmp 2KB
yzm2.bmp 2KB
AdinUserCrtl.class 19KB
GoodsCtrl.class 17KB
OrderCtrl.class 8KB
UserCrtl.class 6KB
OrderInfo.class 3KB
AddOrderServlef.class 3KB
Admin_UpdateGoodsServlet.class 3KB
UpdateOrderZtServlet.class 3KB
GoodsInfo.class 3KB
Admin_AddGoodsServlef.class 3KB
UserInfo.class 3KB
Admin_UpdateYeServlet.class 3KB
Admin_UpdateUserServlet.class 3KB
UpdateUserServlet.class 2KB
LoginServlef.class 2KB
AddCommentServlef.class 2KB
Admin_UpdateYe2Servlet.class 2KB
UpdatePwdServlet.class 2KB
Admin_UpdateAdminServlet.class 2KB
Admin_UpdateZt2.class 2KB
Admin_UpdateNewsServlef.class 2KB
Admin_UpdateLunboImgServlet.class 2KB
AddUserServlef.class 2KB
Admin_LoginServlef.class 2KB
Admin_UpdateSortServlef.class 2KB
Admin_AddUserServlef.class 2KB
Admin_AddNewsServlef.class 2KB
Admin_UpdateSiteServlet.class 2KB
Admin_AddLunboImgServlef.class 2KB
SumInfoCrtl.class 2KB
UpdateAddrServlet.class 2KB
Admin_UpdateLogoImgServlet.class 2KB
Admin_AddSortServlef.class 2KB
Admin_UpdateOrderServlet.class 2KB
Admin_UpdateZt.class 2KB
Admin_deleteAdminUser.class 2KB
Admin_deleteComment.class 2KB
Admin_deleteLunbo.class 2KB
Admin_deleteGoods.class 2KB
Admin_deleteOrder.class 2KB
Admin_deleteSort.class 2KB
Admin_deleteUser.class 2KB
Admin_deleteNews.class 2KB
Admin_UserZxServlet.class 2KB
UserZxServlet.class 2KB
ConnDB.class 1KB
CommentInfo.class 1KB
Admin_NewsInfo.class 1KB
ImgInfo.class 1KB
Admin_UserInfo.class 1KB
GoodsSort.class 741B
SiteInfo.class 730B
.classpath 436B
org.eclipse.wst.jsdt.ui.superType.container 49B
index.css 9KB
adminIndex.css 4KB
login.css 764B
Thumbs.db 414KB
index_gg.gif 22KB
success.gif 11KB
d1.gif 3KB
searchbg.gif 3KB
an_car1.gif 3KB
menubg.gif 2KB
an_js.gif 2KB
search.gif 2KB
d2.gif 2KB
order.gif 2KB
barbg.gif 2KB
db3.gif 2KB
pic_gongxi.gif 2KB
scrollbgn.gif 1KB
rlbg.gif 1KB
icon6.gif 1KB
icon4.gif 1KB
back.gif 749B
next.gif 745B
last.gif 741B
go.gif 736B
first.gif 736B
iconbg.gif 693B
reg_yesno.gif 650B
regbtn.gif 631B
hiconbg.gif 607B
4.gif 598B
icon2.gif 586B
icon3.gif 581B
buybg.gif 569B
btnbg.gif 554B
btnbg.gif 554B
picbg.gif 497B
lgbg.gif 490B
jzz.gif 422B
code.gif 384B
7.gif 353B
1.gif 348B
topbg.gif 336B
reg_yesok.gif 334B
共 318 条
- 1
- 2
- 3
- 4
资源评论
小新要变强
- 粉丝: 2w+
- 资源: 537
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功