当前位置:   article > 正文

基于Java+Mysql的超市管理系统(附源码)_java+mysql项目

java+mysql项目

一、项目介绍

基于Java swing+Mysql实现的超市管理与购物系统,使用了beautyEye_inf.jar美化界面,使用idea编写逻辑代码

项目下载:
gitee下载:https://gitee.com/wusupweilgy/taobao.git
蓝奏云下载:https://wwp.lanzoup.com/i0ZZB0ywnipi
课设报告:https://wwp.lanzoup.com/iZLV20te02cd 提取码:6666
(包括所有代码源文件、第三方库和界面图片)

1.开发环境

jdk8+mysql8+idea

2.功能

1.注册、登录功能。
2.管理员有商品类别管理、商品管理、用户管理、出售记录查询等功能。
3.普通用户有查看购物车、购物卡充值、修改密码、购买商品等功能。

3.项目运行截图

该项目前端界面和后端数据校验博主经过了一系列测试,基本是个比较完善的java课设了,如有不足,希望大家多多建议。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、使用步骤

1.用idea导入项目

通过idea的open打开项目
在这里插入图片描述

2.配置项目jdk版本

ctrl+alt+shift+s 设置项目的jdk版本,两个我这里都选8,必须选择8,如果java版本不对,建议重新下8,因为8比较稳定。
​​​​在这里插入图片描述

3.配置数据库

1)创建shoping数据库,导入运行shoping.sql文件
2)更改db.properties文件,基本只用更改密码,填写自己的数据库密码
在这里插入图片描述

4.运行项目

运行main文件下的Main,输入用户名、密码(都为admin)进入管理员界面,进入普通用户界面需要注册,然后登录

三、项目优点

1.单例模式

项目的每个子窗口都设置了单例模式,为了防止多次点击,创建过多窗口。这里用到了饿汉模式

//单例模式--饿汉模式,只要类被加载,实例就会立刻创建,这样子窗口加载会快一些

//把构造方法变成私有,
private static GoodsTypeAdd goodsTypeAdd = new GoodsTypeAdd();
//获取实例的唯一方式
public static GoodsTypeAdd getGoodsTypeAdd(){
       return goodsTypeAdd;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2.封装了数据库连接类

package utiles;

import java.sql.*;
import java.util.ResourceBundle;

/**
 * 
 */
public class JDBCUtils {
    private static String driver;
    private static String url;
    private static String username;
    private static String password;
    private static ResourceBundle bundle;

	//读取db.properties数据库配置文件
    static{
        bundle = ResourceBundle.getBundle("db");
        driver = bundle.getString("jdbc.driverClass");
        url = bundle.getString("jdbc.jdbcUrl");
        username = bundle.getString("jdbc.username");
        password = bundle.getString("jdbc.password");
    }
 
    /**
     * 
     *
     * @return
     */
    public static Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, username, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }

   
    public static void release(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
  

    public static void release(Connection conn, PreparedStatement pstmt) {
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void release(Connection conn, PreparedStatement pstmt, ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95

3.用户信息读取保存

从数据库读取数据写入本地的文件,一定程度上减少了数据库连接次数

package utiles;

import java.io.*;
import java.util.ArrayList;

public class LoginConfig {

	/**
	 * 将用户的个人信息写入文件
	 * @param name
	 * @param id
	 * @param password
	 */
	public static void writeUser(String name,String id,String password,String money) {
		BufferedWriter bos = null;
			try {
				bos = new BufferedWriter(new FileWriter("password.txt"));
				bos.write(name);
				bos.newLine();
				bos.write(password);
				bos.newLine();
				bos.write(id);
				bos.newLine();
				bos.write(money);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally {
				try {
					if(bos!=null) {
						bos.close();
					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}	
	}
	/**
	 * 返回文件中用户的个人信息集合
	 * @return
	 */
	public static ArrayList<String> getUserList(){
		ArrayList<String> list = new ArrayList();
		BufferedReader bis;
		try {
			bis = new BufferedReader(new FileReader("password.txt"));
			String s = null;
			while((s=bis.readLine())!=null) {
				list.add(s);
			}
		
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
	public static void reset() {
		BufferedWriter bos = null;
			try {
				bos = new BufferedWriter(new FileWriter("password.txt"));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally {
				try {
					if(bos!=null) {
						bos.close();
					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}	
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87

四、个人总结

以上就是我的java课设分享,如果这篇文章有帮助到你,希望可以给作者点个赞 本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/719585

推荐阅读
相关标签