基于Servlet的电子商城购物网站

  • D7_145073
    了解作者
  • 4.5MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-15 12:18
    上传日期
基于Servlet的电子商城购物网站,对于java web开发人员(尤其是新手)是个不错的学习资源。
shop.rar
内容介绍
package com.test.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.test.entity.CommentInfo; import com.test.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 A
评论
    相关推荐
    • web开发 JAVA
      一套PPT,详细讲述了JAVA web开发的细节,带有servlet的讲解
    • Java Web开发
      Java Web开发 Java Web开发 Java Web开发
    • JAVA WEB开发
      模块资源库 项目资源库 实例资源库 等等,感觉还是比较可以的吧,希望对大家能够有帮助
    • Java Web开发
      Java Web开发Java Web开发Java Web开发Java Web开发Java Web开发
    • java web开发
      java web开发
    • java WEB开发
      J2EE技术PPT资料_041013
    • JAVA WEB开发
      基于Java WEB 技术的基础讲解文档
    • Java Web开发
      软件开发,IT认证,网络软件
    • java web开发
      java web开发整套教程
    • java web开发
      这个文档对于学习java web的人来说很好,很浅显易懂,学习java开发人员可以看看,讲的挺好的,可以用于J2EE的面试