赞
踩
源码编号:F-A14
项目类型:Java SE项目(GUI图形界面)
项目名称:商城购物系统,开源免费
用户类型:双角色(会员、管理员)
主要技术:java、awt、swing、等技术
开发工具:Eclipse
运行工具:Eclipse/MyEclipse/IDEA都可以,eclipse最兼容
数 据 库:MySQL5.7以上
项目简介:本系统主要的功能有会员注册、登录、商品种类管理、商品管理、浏览商品、以及购物车等操作。
以下是部分截图
项目骨架
主界面
登录
添加商品类别
商品管理
以下是核心代码
- package com.dao;
-
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
-
- import com.model.Customer;
- import com.model.ManagerUser;
-
- public class CustomerUserDao {
-
- public int customerAdd(Connection con,Customer customer)throws Exception{
- String sql="insert into t_customer values(null,?,?,?,?)";
- PreparedStatement pstmt=con.prepareStatement(sql);
- pstmt.setString(1, customer.getCustomerName());
- pstmt.setString(2, customer.getPassword1());
- pstmt.setString(3, customer.getPassword2());
- pstmt.setFloat(4, customer.getMoney());
- return pstmt.executeUpdate();
- }
-
-
- public Customer login(Connection con, Customer customer)throws Exception{
- Customer resultUser=null;
- String sql="select * from t_customer where customerName=? and password1=?";
- PreparedStatement pstmt=con.prepareStatement(sql);
- pstmt.setString(1, customer.getCustomerName());
- pstmt.setString(2,customer.getPassword1());
- ResultSet rs=pstmt.executeQuery();
- if(rs.next()){
- resultUser=new Customer();
- resultUser.setCustomerName(rs.getString("customerName"));
- resultUser.setPassword1(rs.getString("password1"));
- }
- return resultUser;
- }
- }

以下是部分核心代码
- package com.dao;
-
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
-
- import com.model.Product;
- import com.util.StringUtil;
-
- public class ProductDao {
-
- public int productAdd(Connection con,Product product)throws Exception{
- String sql="insert into t_product values(null,?,?,?,?,?)";
- PreparedStatement pstmt=con.prepareStatement(sql);
- pstmt.setString(1, product.getProductName());
- pstmt.setString(2,product.getProductTime());
- pstmt.setFloat(3, product.getPrice());
- pstmt.setString(4, product.getProductDesc());
- pstmt.setInt(5, product.getProductTypeId());
- return pstmt.executeUpdate();
-
- }
- public int productAddIntoCar(Connection con,Product product)throws Exception{
- String sql="insert into t_productchosen values(null,?,?,?,?,?)";
- PreparedStatement pstmt=con.prepareStatement(sql);
- pstmt.setString(1, product.getProductName());
- pstmt.setString(2,product.getProductTime());
- pstmt.setFloat(3, product.getPrice());
- pstmt.setString(4, product.getProductDesc());
- pstmt.setInt(5, product.getProductTypeId());
- return pstmt.executeUpdate();
-
- }
- //如果是罗列的话,只需con就行了
- public ResultSet productList(Connection con,Product product)throws Exception{
- StringBuffer sb=new StringBuffer("select * from t_product p,t_productType pt where p.productTypeId=pt.id ");
- if(StringUtil.isNotEmtpty(product.getProductName())){
- sb.append(" and p.productName like '%"+product.getProductName()+"%'");
- }//查询语句的经典算法, 设置数据文件的搜索路径append
- if(StringUtil.isNotEmtpty(product.getProductTime())){
- sb.append(" and p.productTime like '%"+product.getProductTime()+"%'");
- }//查询语句的经典算法, 设置数据文件的搜索路径append
- if(product.getProductTypeId()!=-1){
- sb.append(" and p.productTypeId ="+product.getProductTypeId());
- }//查询语句的经典算法, 设置数据文件的搜索路径append
- PreparedStatement pstmt=con.prepareStatement(sb.toString());
- return pstmt.executeQuery();
- }
- public ResultSet productChosenList(Connection con)throws Exception{
- String sql="select * from t_productchosen p,t_productType pt where p.productTypeId=pt.id ";
- PreparedStatement pstmt=con.prepareStatement(sql);
- return pstmt.executeQuery();
- }
- public int productDelete(Connection con,String id)throws Exception{
- String sql="delete from t_product where id=?";
- PreparedStatement pstmt=con.prepareStatement(sql);
- pstmt.setString(1, id);
- return pstmt.executeUpdate();
- }
- public int productChosenDelete(Connection con,String id)throws Exception{
- String sql="delete from t_productchosen where id=?";
- PreparedStatement pstmt=con.prepareStatement(sql);
- pstmt.setString(1, id);
- return pstmt.executeUpdate();
- }
-
- public int productModify(Connection con,Product product)throws Exception{
- String sql="update t_product set productName=?,productTime=?,price=?,productDesc=?,productTypeId=? where id=?";
- PreparedStatement pstmt=con.prepareStatement(sql);
- pstmt.setString(1, product.getProductName());
- pstmt.setString(2, product.getProductTime());
- pstmt.setFloat(3, product.getPrice());
- pstmt.setString(4, product.getProductDesc());
- pstmt.setInt(5, product.getProductTypeId());
- pstmt.setInt(6, product.getId());
- return pstmt.executeUpdate();
- }
- public boolean getProductByProductTypeId(Connection con,String productTypeId)throws Exception{
- String sql="select * from t_product where productTypeId=?";
- PreparedStatement pstmt=con.prepareStatement(sql);
- pstmt.setString(1, productTypeId);
- ResultSet rs=pstmt.executeQuery();
- return rs.next();
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。