当前位置:   article > 正文

基于Java的商城购物系统_购物管理系统java代码

购物管理系统java代码

源码编号:F-A14

项目类型:Java SE项目(GUI图形界面

项目名称:商城购物系统,开源免费

用户类型:双角色(会员、管理员)

主要技术:java、awt、swing、等技术

开发工具:Eclipse

运行工具:Eclipse/MyEclipse/IDEA都可以,eclipse最兼容

数  据  库:MySQL5.7以上

项目简介:本系统主要的功能有会员注册、登录、商品种类管理、商品管理、浏览商品、以及购物车等操作。

以下是部分截图

项目骨架

主界面

登录

添加商品类别

商品管理

以下是核心代码

  1. package com.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import com.model.Customer;
  6. import com.model.ManagerUser;
  7. public class CustomerUserDao {
  8. public int customerAdd(Connection con,Customer customer)throws Exception{
  9. String sql="insert into t_customer values(null,?,?,?,?)";
  10. PreparedStatement pstmt=con.prepareStatement(sql);
  11. pstmt.setString(1, customer.getCustomerName());
  12. pstmt.setString(2, customer.getPassword1());
  13. pstmt.setString(3, customer.getPassword2());
  14. pstmt.setFloat(4, customer.getMoney());
  15. return pstmt.executeUpdate();
  16. }
  17. public Customer login(Connection con, Customer customer)throws Exception{
  18. Customer resultUser=null;
  19. String sql="select * from t_customer where customerName=? and password1=?";
  20. PreparedStatement pstmt=con.prepareStatement(sql);
  21. pstmt.setString(1, customer.getCustomerName());
  22. pstmt.setString(2,customer.getPassword1());
  23. ResultSet rs=pstmt.executeQuery();
  24. if(rs.next()){
  25. resultUser=new Customer();
  26. resultUser.setCustomerName(rs.getString("customerName"));
  27. resultUser.setPassword1(rs.getString("password1"));
  28. }
  29. return resultUser;
  30. }
  31. }

以下是部分核心代码

  1. package com.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import com.model.Product;
  6. import com.util.StringUtil;
  7. public class ProductDao {
  8. public int productAdd(Connection con,Product product)throws Exception{
  9. String sql="insert into t_product values(null,?,?,?,?,?)";
  10. PreparedStatement pstmt=con.prepareStatement(sql);
  11. pstmt.setString(1, product.getProductName());
  12. pstmt.setString(2,product.getProductTime());
  13. pstmt.setFloat(3, product.getPrice());
  14. pstmt.setString(4, product.getProductDesc());
  15. pstmt.setInt(5, product.getProductTypeId());
  16. return pstmt.executeUpdate();
  17. }
  18. public int productAddIntoCar(Connection con,Product product)throws Exception{
  19. String sql="insert into t_productchosen values(null,?,?,?,?,?)";
  20. PreparedStatement pstmt=con.prepareStatement(sql);
  21. pstmt.setString(1, product.getProductName());
  22. pstmt.setString(2,product.getProductTime());
  23. pstmt.setFloat(3, product.getPrice());
  24. pstmt.setString(4, product.getProductDesc());
  25. pstmt.setInt(5, product.getProductTypeId());
  26. return pstmt.executeUpdate();
  27. }
  28. //如果是罗列的话,只需con就行了
  29. public ResultSet productList(Connection con,Product product)throws Exception{
  30. StringBuffer sb=new StringBuffer("select * from t_product p,t_productType pt where p.productTypeId=pt.id ");
  31. if(StringUtil.isNotEmtpty(product.getProductName())){
  32. sb.append(" and p.productName like '%"+product.getProductName()+"%'");
  33. }//查询语句的经典算法, 设置数据文件的搜索路径append
  34. if(StringUtil.isNotEmtpty(product.getProductTime())){
  35. sb.append(" and p.productTime like '%"+product.getProductTime()+"%'");
  36. }//查询语句的经典算法, 设置数据文件的搜索路径append
  37. if(product.getProductTypeId()!=-1){
  38. sb.append(" and p.productTypeId ="+product.getProductTypeId());
  39. }//查询语句的经典算法, 设置数据文件的搜索路径append
  40. PreparedStatement pstmt=con.prepareStatement(sb.toString());
  41. return pstmt.executeQuery();
  42. }
  43. public ResultSet productChosenList(Connection con)throws Exception{
  44. String sql="select * from t_productchosen p,t_productType pt where p.productTypeId=pt.id ";
  45. PreparedStatement pstmt=con.prepareStatement(sql);
  46. return pstmt.executeQuery();
  47. }
  48. public int productDelete(Connection con,String id)throws Exception{
  49. String sql="delete from t_product where id=?";
  50. PreparedStatement pstmt=con.prepareStatement(sql);
  51. pstmt.setString(1, id);
  52. return pstmt.executeUpdate();
  53. }
  54. public int productChosenDelete(Connection con,String id)throws Exception{
  55. String sql="delete from t_productchosen where id=?";
  56. PreparedStatement pstmt=con.prepareStatement(sql);
  57. pstmt.setString(1, id);
  58. return pstmt.executeUpdate();
  59. }
  60. public int productModify(Connection con,Product product)throws Exception{
  61. String sql="update t_product set productName=?,productTime=?,price=?,productDesc=?,productTypeId=? where id=?";
  62. PreparedStatement pstmt=con.prepareStatement(sql);
  63. pstmt.setString(1, product.getProductName());
  64. pstmt.setString(2, product.getProductTime());
  65. pstmt.setFloat(3, product.getPrice());
  66. pstmt.setString(4, product.getProductDesc());
  67. pstmt.setInt(5, product.getProductTypeId());
  68. pstmt.setInt(6, product.getId());
  69. return pstmt.executeUpdate();
  70. }
  71. public boolean getProductByProductTypeId(Connection con,String productTypeId)throws Exception{
  72. String sql="select * from t_product where productTypeId=?";
  73. PreparedStatement pstmt=con.prepareStatement(sql);
  74. pstmt.setString(1, productTypeId);
  75. ResultSet rs=pstmt.executeQuery();
  76. return rs.next();
  77. }
  78. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/827383
推荐阅读
相关标签
  

闽ICP备14008679号