首页>代码>java web开发在线电商购物车系统(jsp+jdbc+spring mvc+bootstrap)>/Ebdb-client/src/com/dspt/dao/impl/GoodsDaoImpl.java
package com.dspt.dao.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.dspt.dao.intf.I_GoodsDao; import com.dspt.entity.GoodsBean; import com.dspt.util.DBUtil; /*商品增删改查实现类*/ public class GoodsDaoImpl implements I_GoodsDao { public Connection conn; public PreparedStatement pst; public ResultSet rs; /*查询每个大类中小类的具体商品*/ /*Timestamp转String*/ public static String gettime(Timestamp ts){ SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Long longtime=ts.getTime(); Date date=new Date(longtime); return sdf.format(date); } //服务端连接数据库查找对应的商品信息,根据当前页每页显示8条数据 @Override public List<GoodsBean> findgoodsall(int currentpage,String goodstype) throws Exception { List<GoodsBean> list=new ArrayList<GoodsBean>(); GoodsBean goodsbean=null; try { String sql="select * from goodsinfo where goodstype=? limit ?,10"; conn=DBUtil.getConnection(); pst=conn.prepareStatement(sql); pst.setString(1,goodstype); pst.setInt(2,(currentpage-1)*8); rs=pst.executeQuery(); while(rs.next()){ goodsbean=new GoodsBean(); goodsbean.setGid(rs.getInt("gid")); goodsbean.setGkey(rs.getString("gkey")); goodsbean.setGname(rs.getString("gname")); goodsbean.setGcolor(rs.getString("gcolor")); goodsbean.setGspec(rs.getString("gspec")); goodsbean.setGweight(rs.getFloat("gweight")); goodsbean.setGpic(rs.getBytes("gpic")); goodsbean.setGarea(rs.getString("garea")); goodsbean.setGmaker(rs.getString("gmaker")); goodsbean.setGdatetime(gettime(rs.getTimestamp("gdate")));//使用实体类的String的时间获取rs得到的数据库的Timestamp型的时间 goodsbean.setGprice(rs.getFloat("gprice")); goodsbean.setGhotprice(rs.getFloat("ghotprice")); goodsbean.setIs_push(rs.getBoolean("is_push")); goodsbean.setGmout(rs.getInt("gmount")); goodsbean.setGindatetime(gettime(rs.getTimestamp("gindate"))); goodsbean.setAccount(rs.getFloat("account")); goodsbean.setGoodstype(rs.getString("goodstype")); list.add(goodsbean);//返回list } return list; }finally{ DBUtil.close(rs); DBUtil.close(pst); DBUtil.close(conn); } } /*根据点击的商品类型进行查找数据库相对应的商品的行数并返回*/ @Override public int findcout(String goodstype) throws Exception { String sql="select count(*) from goodsinfo where goodstype=? "; conn=DBUtil.getConnection(); pst=conn.prepareStatement(sql); pst.setString(1,goodstype); rs=pst.executeQuery(); int num=0; if(rs.next()){ //取查询到的数据 num=rs.getInt(1); } System.out.println(num); return num; } }

xiao1111 LV3
2024年6月18日
2036495585 LV9
2023年10月6日
lzlzyw LV14
2022年3月24日
jdndbh LV6
2021年12月19日
憨代写 LV2
2021年12月5日
〖怪咖〗 LV7
2021年4月11日
1771658781 LV5
2020年12月27日
Demo1111 LV30
2020年12月17日
tnrthr LV6
2020年12月16日
uuu33442 LV4
2020年11月3日

微信网友_7309216833228800 LV1
2024年12月23日
592132324 LV4
2024年12月11日
suhe_5254
2024年12月1日
暂无贡献等级
小黄同学 LV8
2024年9月29日
xiao1111 LV3
2024年6月18日
韩韩hssfdfd
2024年6月5日
暂无贡献等级
zolscy LV24
2024年3月25日
a2418735612 LV1
2024年1月4日
微信网友_6797846869299200 LV7
2024年1月1日
lwqzyx LV1
2023年12月22日