//这是model类,完成对货物表的处理
package com.zhang.model;
import java.sql.*;
import java.util.*;
public class GoodsBeanBo {
//定义一些变量
private ResultSet rs = null;
private Connection ct = null;
private PreparedStatement ps = null;
public int getTypeCount(int pageSize,int smallId){
int pageCount = 0;
int rowCount = 0;
try{
ct = new ConDB().getConnection();
ps = ct.prepareStatement("select count(*) from goods where smallId=?");
ps.setInt(1, smallId);
rs = ps.executeQuery();
if(rs.next()){
rowCount = rs.getInt(1);
}
if(rowCount%pageSize == 0){
pageCount = rowCount/pageSize;
}else{
pageCount = rowCount/pageSize+1;
}
}catch(Exception e){
e.printStackTrace();
}finally{
this.close();
}
// System.out.print("pagecount ="+pageCount);
return pageCount;
}
public int getPageCount(int pageSize){
int pageCount = 0;
int rowCount = 0;
try{
ct = new ConDB().getConnection();
ps = ct.prepareStatement("select count(*) from goods");
rs = ps.executeQuery();
if(rs.next()){
rowCount = rs.getInt(1);
}
if(rowCount%pageSize == 0){
pageCount = rowCount/pageSize;
}else{
pageCount = rowCount/pageSize+1;
}
}catch(Exception e){
e.printStackTrace();
}finally{
this.close();
}
return pageCount;
}
//分页显示功能
public ArrayList getGoodsByPage(int pageSize,int pageNow){
ArrayList a1 = new ArrayList();
try{
ct = new ConDB().getConnection();
ps = ct.prepareStatement("select *from goods order by goodsId limit "+(pageNow-1)*6+","+pageNow*pageSize+"");
rs = ps.executeQuery();
while(rs.next()){
GoodsBean gb = new GoodsBean();
gb.setGoodsId(rs.getInt(1));
gb.setSmallId(rs.getInt(2));
gb.setGoodName(rs.getString(3));
gb.setIntroduce(rs.getString(4));
gb.setCreateTime(rs.getString(5));
gb.setNowPrice(rs.getFloat(6));
gb.setStore(rs.getInt(7));
gb.setDiscount(rs.getFloat(8));
gb.setNumber(rs.getInt(9));
gb.setPicName(rs.getString(10));
a1.add(gb);
}
}catch(Exception e){
e.printStackTrace();
}finally{
this.close();
}
return a1;
}
public ArrayList getGoodsByType(int pageSize,int pageNow,int smallId){
System.out.print(smallId);
ArrayList a1 = new ArrayList();
try{
ct = new ConDB().getConnection();
ps = ct.prepareStatement("select *from goods where smallId = "+smallId+" order by goodsId limit "+(pageNow-1)*6+","+pageNow*pageSize+"");
rs = ps.executeQuery();
boolean b=rs.next();
while(b){
GoodsBean gb = new GoodsBean();
gb.setGoodsId(rs.getInt(1));
gb.setSmallId(rs.getInt(2));
gb.setGoodName(rs.getString(3));
gb.setIntroduce(rs.getString(4));
gb.setCreateTime(rs.getString(5));
gb.setNowPrice(rs.getFloat(6));
gb.setStore(rs.getInt(7));
gb.setDiscount(rs.getFloat(8));
gb.setNumber(rs.getInt(9));
gb.setPicName(rs.getString(10));
a1.add(gb);
}
}catch(Exception e){
e.printStackTrace();
}finally{
this.close();
}
/* System.out.print(smallId);
System.out.print(" ");
System.out.print(a1.size());*/
return a1;
}
//根据商品的货物ID,得到商品的具体的信息
public GoodsBean getGoodsBean(String id){
GoodsBean gb = new GoodsBean();
try{
ct = new ConDB().getConnection();
ps = ct.prepareStatement("select * from goods where goodsId = ? ");
ps.setString(1, id);
rs = ps.executeQuery();
if(rs.next()){
gb.setGoodsId(rs.getInt(1));
gb.setSmallId(rs.getInt(2));
gb.setGoodName(rs.getString(3));
gb.setIntroduce(rs.getString(4));
gb.setCreateTime(rs.getString(5));
gb.setNowPrice(rs.getFloat(6));
gb.setStore(rs.getInt(7));
gb.setDiscount(rs.getFloat(8));
gb.setNumber(rs.getInt(9));
gb.setPicName(rs.getString(10));
//放入GoodBean
}
}catch(Exception e){
e.printStackTrace();
}finally{
this.close();
}
return gb;
}
//得到所有商品信息
public ArrayList getGoods(){
ArrayList a1=new ArrayList();
try{
ct = new ConDB().getConnection();
ps = ct.prepareStatement("select * from goods");
rs = ps.executeQuery();
while(rs.next()){
GoodsBean gb = new GoodsBean();
gb.setGoodsId(rs.getInt(1));
gb.setSmallId(rs.getInt(2));
gb.setGoodName(rs.getString(3));
gb.setIntroduce(rs.getString(4));
gb.setCreateTime(rs.getString(5));
gb.setNowPrice(rs.getFloat(6));
gb.setStore(rs.getInt(7));
gb.setDiscount(rs.getFloat(8));
gb.setNumber(rs.getInt(9));
gb.setPicName(rs.getString(10));
a1.add(gb);
//放入GoodBean
}
}catch(Exception e){
e.printStackTrace();
}finally{
this.close();
}
System.out.print("first="+a1.size());
return a1;
}
//删除单个商品
public boolean delOneGood(int goodsId){
boolean b = false;
try{
ct = new ConDB().getConnection();
ps = ct.prepareStatement("delete from goods where goodsId=?");
ps.setInt(1, goodsId);
int k = ps.executeUpdate();
if(k==1){
b=true;
}
}catch(Exception e){
e.printStackTrace();
}finally{
this.close();
}
return b;
}
//添加商品
public boolean add(String smallName,String goodsName,String introduce,float price,String picName ){
boolean b=false;
int smallId;
try{
ct = new ConDB().getConnection();
ps=ct.prepareStatement("select smallId from smallType where smallName=?");
ps.setString(1, smallName);
rs=ps.executeQuery();
if(rs.next()){
smallId =rs.getInt(1);
ps = ct.prepareStatement("insert into goods(smallId,goodName,introduce,nowPrice,picName)values (?,?,?,?,?)");
ps.setInt(1, smallId);
ps.setString(2, goodsName);
ps.setString(3, introduce);
ps.setFloat(4, price);
ps.setString(5, picName);
int k =ps.executeUpdate();
if(k==1){
b=true;
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
this.close();
}
return b;
}
//关闭函数
public void close(){
try{
if(rs!=null){
rs.close();
rs = null;
}
if(ps !=null){
ps.close();
ps = null;
}
if(ct.isClosed()){
ct.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于jsp的网上商城项目
共253个文件
gif:107个
jpg:31个
jsp:30个
需积分: 13 27 下载量 103 浏览量
2011-07-02
13:59:37
上传
评论 1
收藏 936KB RAR 举报
温馨提示
该项目是基于jsp的网上商城 分为客户端和服务器端 顾客可浏览商品 购买商品 添加购物车 生成订单 缺货登记等 管理员可管理商品 修改订单状态等 系统还提供了缺货预警功能
资源推荐
资源详情
资源评论
收起资源包目录
基于jsp的网上商城项目 (253个子文件)
GoodsBeanBo.class 6KB
OrderBeanBo.class 6KB
MyCarBo.class 4KB
TypeBo.class 3KB
QueryBeanBo.class 3KB
ShoppingServlet.class 3KB
OrderClServlet.class 3KB
UserBeanBo.class 2KB
LoginServlet.class 2KB
AdminOrderServlet.class 2KB
TypeShowServlet.class 2KB
OrderInfoBean.class 2KB
AdminBeanBo.class 2KB
GoodsBean.class 2KB
AdminGoodsServlet.class 2KB
ShowGoodsServlet.class 2KB
QueryServlet.class 2KB
AdminLoginServlet.class 2KB
UserBean.class 2KB
ShowOrderBean.class 2KB
OrderBean.class 2KB
ShoppingNeServlet.class 2KB
ConDB.class 1KB
filter.class 1KB
SmallTypeBean.class 957B
AdminBean.class 945B
OrderDetailBean.class 895B
BigTypeBean.class 757B
.classpath 446B
org.eclipse.wst.jsdt.ui.superType.container 49B
base.css 5KB
main.css 1KB
menu.css 1005B
my.css 459B
login_09.gif 22KB
login_04.gif 19KB
name.gif 16KB
login_06.gif 14KB
tubiao.gif 10KB
unite_header_1101.gif 10KB
14.gif 10KB
15.gif 10KB
logo1.gif 7KB
login_05.gif 7KB
main_09.gif 6KB
login_03.gif 5KB
logo.gif 5KB
main_08.gif 5KB
login_10.gif 5KB
left_tree.gif 5KB
login_08.gif 5KB
logo.gif 3KB
login.gif 3KB
b.gif 3KB
dangdang.gif 3KB
main_30.gif 3KB
main_40.gif 3KB
main_03.gif 3KB
menu_top.gif 3KB
login_07.gif 2KB
13.gif 2KB
main_32.gif 2KB
clothes.gif 2KB
phone.gif 2KB
ico_spider.gif 2KB
qc.gif 2KB
main_04.gif 2KB
main_28.gif 2KB
main_31_1.gif 2KB
main_29_1.gif 2KB
hotshow.gif 2KB
main_26_1.gif 2KB
main_26.gif 2KB
denglu.gif 2KB
order.gif 2KB
main_29.gif 2KB
main_06.gif 2KB
menubg.gif 2KB
main_22.gif 2KB
main_48.gif 2KB
main_47.gif 2KB
tejia.gif 2KB
pinpai.gif 2KB
16.gif 1KB
fenlei.gif 1KB
main_20.gif 1KB
main_18.gif 1KB
main_12.gif 1KB
main_11.gif 1KB
main_14.gif 1KB
main_16.gif 1KB
book.gif 1KB
topitembg.gif 1020B
dl.gif 984B
shopcar.gif 856B
main_58.gif 804B
sp_bg.gif 705B
main_07.gif 701B
main_01.gif 682B
main_37.gif 661B
共 253 条
- 1
- 2
- 3
资源评论
lafite1990
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功