一、概述

为了管理好商店库存信息,提升店铺管理工作效率,结合实际工作需要,设计和开发本系统,主要用于商店商品信息维护出入库等。包含商品库存信息查看、商品信息修改,新增商品信息,删除信息等功能。

二、功能清单

1、查询如图

查询界面,请从数据库查询学生信息表数据并显示在控件上,通过底部功能菜单执行相应功能,添加、修改按钮点击后课弹出相应窗体执行相应操作,点击刷新按钮课刷新当前数据,删除按钮点击后可删除选中行数据并刷新

2、添加,如图

填写姓名和班级后,点击添加按钮后可添加数据

3、修改,如图

通过点击查询界面中“修改按钮”,可在修改界面修改当前选中行数据

三、数据库

注意:数据库名称为“班级_姓名”,如“1705_小白”。

表名称:tGoods

字段

字段名

数据类型

描述

约束

goodsID

int

商品编号

主键自增长

name

varchar(20)

商品名称

typeName

varchar(20)

类别名称

stock

Int

库存

评分规则(共100分)

标题

分值

合理注释

10分

命名规范

10分

查询

20分

修改

10分

删除

10分

添加

10分

数据库创建

10分

数据库连接

10分

整体效果

10分

实现代码:

数据库 链接:https://pan-yz.chaoxing.com/external/m/file/483246110958415872

Java文件 链接:https://pan-yz.chaoxing.com/external/m/file/483246085097291776

数据库:

-- ----------------------------
-- Table structure for tgoods
-- ----------------------------
DROP TABLE IF EXISTS `tgoods`;
CREATE TABLE `tgoods` (
`goodsID` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`typeName` varchar(20) DEFAULT NULL,
`stock` int(11) DEFAULT NULL,
PRIMARY KEY (`goodsID`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; -- ----------------------------
-- Records of tgoods
-- ----------------------------
INSERT INTO `tgoods` VALUES ('9', '统一冰红茶', '饮料', '24');
INSERT INTO `tgoods` VALUES ('10', '娃哈哈营养快线', '饮料', '23');

com.test.db >>> DbConnection

package com.test.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException; import com.mysql.jdbc.Statement; public class DbConnection {
//驱动类的类名
private static final String DRIVERNAME="com.mysql.jdbc.Driver";
//连接数据的URL路径
private static final String URL="jdbc:mysql://localhost:3306/1902_杨明金";
//数据库登录账号
private static final String USER="root";
//数据库登录密码
private static final String PASSWORD="root123";
//加载驱动
static{
try {
Class.forName(DRIVERNAME);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//获取数据库连接
public static Connection getConnection() {
try {
return DriverManager.getConnection(URL,USER,PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
//查询
public static ResultSet query(String sql) {
System.out.println(sql);
//获取连接
Connection connection=getConnection();
PreparedStatement psd;
try {
psd = connection.prepareStatement(sql);
return psd.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
//增、删、改、查
public static int updataInfo(String sql) {
System.out.println(sql);
//获取连接
Connection connection=getConnection();
try {
PreparedStatement psd=connection.prepareStatement(sql);
return psd.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
return 0;
}
//关闭连接
public static void colse(ResultSet rs,Statement stmt,Connection conn) throws Exception{
try { if (rs != null){ rs.close(); }
if (stmt != null) { stmt.cancel(); }
if (conn != null) { conn.close(); }
} catch (Exception e) {
e.printStackTrace(); throw new Exception();
}
}
}

com.test.entity >>> Goods

package com.test.entity;

public class Goods {
private int goodsID;//商品ID
private String name;//商品名称
private String typeName;//商品类别
private int stock;//库存 public Goods(int goodsID, String name, String typeName, int stock) {
super();
this.goodsID = goodsID;
this.name = name;
this.typeName = typeName;
this.stock = stock;
} public Goods() {
super();
} public int getGoodsID() {
return goodsID;
} public void setGoodsID(int goodsID) {
this.goodsID = goodsID;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getTypeName() {
return typeName;
} public void setTypeName(String typeName) {
this.typeName = typeName;
} public int getStock() {
return stock;
} public void setStock(int stock) {
this.stock = stock;
} }

com.test.controller >>> Updata

package com.test.controller;

import com.test.db.DbConnection;

public class Updata {
//添加数据
public static int addData(String sql) { return DbConnection.updataInfo(sql);
}
}

com.test.controller >>> Select

package com.test.controller;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import com.test.db.DbConnection;
import com.test.entity.Goods; public class Select {
public static Object[][] getGoods() {
String sql = "SELECT * FROM tgoods"; ResultSet resultSet = DbConnection.query(sql);
ArrayList<Goods> list=new ArrayList<Goods>();
try {
while (resultSet.next()) {
Goods goods=new Goods();
goods.setGoodsID(resultSet.getInt(1));
goods.setName(resultSet.getString(2));
goods.setTypeName(resultSet.getString(3));
goods.setStock(resultSet.getInt(4));
list.add(goods);
}
} catch (SQLException e) {
e.printStackTrace();
}
Object[][] objects=new Object[list.size()][4];
for(int i=0;i<list.size();i++) {
objects[i][0]=list.get(i).getGoodsID();
objects[i][1]=list.get(i).getName();
objects[i][2]=list.get(i).getTypeName();
objects[i][3]=list.get(i).getStock();
}
return objects;
} }

com.test.View >>> IndexGUI

package com.test.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel; import com.test.controller.Select;
import com.test.controller.Updata;
import com.test.entity.Goods; public class IndexGUI extends JFrame { Object[] columnNames = {"商品编号","名称","类别名称","库存"};
Object[][] data = Select.getGoods();
DefaultTableModel df = new DefaultTableModel(data, columnNames); public IndexGUI() {
super("商品信息管理");
this.setBounds(0, 0, 780, 500);
this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
this.setResizable(false);//让窗口大小不可改变
this.setLayout(null); JTable jTable=new JTable(df);
JScrollPane jp = new JScrollPane(jTable);
jp.setBounds(0, 10, 780, 350);
this.add(jp); JButton tj = new JButton("添加");
tj.setBounds(50, 400, 100, 30);
tj.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
IncreaseGUL i = new IncreaseGUL();
i.setVisible(true);
}
}); JButton sc = new JButton("删除");
sc.setBounds(180, 400, 100, 30);
sc.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jTable.getSelectedColumn()<0) {
JOptionPane.showMessageDialog(null, "请选中要删除的数据!");
} else {
int goodsID = Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 0).toString());
String sql="delete from tgoods where goodsid="+goodsID;
Updata updata = new Updata();
int result = updata.addData(sql);
if (result>0) {
JOptionPane.showMessageDialog(null, "删除成功!");
JOptionPane.showMessageDialog(null, "记得刷新一下哦!");
} else {
JOptionPane.showMessageDialog(null, "删除失败!");
}
}
}
}); JButton xg = new JButton("修改");
xg.setBounds(310, 400, 100, 30);
xg.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jTable.getSelectedColumn()<0) {
JOptionPane.showMessageDialog(null, "请选择要修改的数据!");
} else {
int goodsID = Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 0).toString());
String name = jTable.getValueAt(jTable.getSelectedRow(), 1).toString();
String typeName = jTable.getValueAt(jTable.getSelectedRow(), 2).toString();
int stock = Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 3).toString());
Goods goods = new Goods(goodsID,name,typeName,stock);
ModifyGUI modifyGUI = new ModifyGUI(goods);
modifyGUI.setVisible(true);
} }
}); JButton sx = new JButton("刷新");
sx.setBounds(440, 400, 100, 30);
sx.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Object[][] data = Select.getGoods();
df.setDataVector(data, columnNames);
}
}); this.add(tj);
this.add(sc);
this.add(xg);
this.add(sx);
} }

com.test.View >>> IncreaseGUL

package com.test.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField; import com.test.controller.Updata; public class IncreaseGUL extends JFrame implements ActionListener {
JTextField name = new JTextField();
JTextField type = new JTextField();
JTextField num = new JTextField();
public IncreaseGUL() {
super.setTitle("添加商品");
this.setBounds(0, 0, 780, 250);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setLayout(null); JLabel nameT = new JLabel("名称");
nameT.setBounds(50, 30, 40, 25);
name.setBounds(100, 30, 145, 30); JLabel typeT = new JLabel("类别");
typeT.setBounds(280, 30, 40, 25);
type.setBounds(335, 30, 145, 30); JLabel numT = new JLabel("数量");
numT.setBounds(515, 30, 40, 25);
num.setBounds(575, 30, 145, 30); JButton tj = new JButton("添加");
tj.setBounds(100, 115, 100, 30);
tj.addActionListener(this); this.add(nameT);
this.add(name);
this.add(typeT);
this.add(type);
this.add(numT);
this.add(num);
this.add(tj);
} @Override
public void actionPerformed(ActionEvent e) {
String sql = null;
String addName = name.getText();
String addType = type.getText();
String addNum = num.getText();
if (addName.equals("")||addType.equals("")||addNum.equals("")) {
JOptionPane.showMessageDialog(null, "请完整输入要添加的数据");
} else {
sql="INSERT INTO tgoods VALUES("+"null,'"+addName+"','"+addType+"','"+addNum+"')";
int result = Updata.addData(sql);
if (result>0) {
JOptionPane.showMessageDialog(null, "添加成功!");
JOptionPane.showMessageDialog(null, "记得刷新一下哦!");
dispose();
IndexGUI i = new IndexGUI();
} else {
JOptionPane.showMessageDialog(null, "添加失败!");
}
}
}
}

com.test.View >>> ModifyGUI

package com.test.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import com.test.controller.Updata;
import com.test.entity.Goods; public class ModifyGUI extends JFrame implements ActionListener { JTextField name = new JTextField();
JTextField type = new JTextField();
JTextField num = new JTextField();
int id;
public ModifyGUI(Goods goods) {
super.setTitle("修改商品");
this.setBounds(0, 0, 780, 250);
this.setLocationRelativeTo(null);
this.setLayout(null); JLabel nameT = new JLabel("名称");
nameT.setBounds(50, 30, 40, 25);
name.setBounds(100, 30, 145, 30); JLabel typeT = new JLabel("类别");
typeT.setBounds(280, 30, 40, 25);
type.setBounds(335, 30, 145, 30); JLabel numT = new JLabel("库存");
numT.setBounds(515, 30, 40, 25);
num.setBounds(575, 30, 145, 30); JButton xg = new JButton("修改");
xg.setBounds(100, 115, 100, 30);
xg.addActionListener(this); this.add(nameT);
this.add(name);
this.add(typeT);
this.add(type);
this.add(numT);
this.add(num);
this.add(xg); name.setText(goods.getName());
type.setText(goods.getTypeName());
num.setText(Integer.toString(goods.getStock()));
id = goods.getGoodsID();
} @Override
public void actionPerformed(ActionEvent e) {
String sql = null;
String addName = name.getText();
String addType = type.getText();
int addNum = Integer.parseInt(num.getText());
if (addName.equals("")||addType.equals("")||addNum==0) {
JOptionPane.showMessageDialog(null, "请完整输入要修改的数据");
}else {
Updata up=new Updata(); sql="UPDATE tgoods SET "+"name='"+addName+"',typeName='"+addType+"',stock='"+addNum+"'where goodsid="+id;
int result = Updata.addData(sql);
Updata.addData(sql);
if (result>0) {
JOptionPane.showMessageDialog(null, "修改成功!");
JOptionPane.showMessageDialog(null, "记得刷新一下哦!");
dispose();
IndexGUI i = new IndexGUI();
i.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "修改失败!");
}
}
}
}

com.test.Test >>> Test

package com.test.Test;

import com.test.view.IndexGUI;

public class Test {
public static void main(String[] args) {
IndexGUI i = new IndexGUI();
i.setVisible(true);
}
}

Java Swing设计简单商品信息管理系统(java swing+mysql+eclipse)的更多相关文章

  1. 【Java Web】简易商品信息管理系统——首个Web项目

    正文之前 在学习了一段时间的Java Web的内容之后,当然需要有个项目来练练手,我相信大多数人的首选项目都是信息管理系统吧,所以我选择了商品信息管理系统 目前项目源码已全部上传至GitHub,欢迎大 ...

  2. 简易商品信息管理系统——首个Web项目

    正文之前 在学习了一段时间的Java Web的内容之后,当然需要有个项目来练练手,我相信大多数人的首选项目都是信息管理系统吧,所以我选择了商品信息管理系统 目前项目源码已全部上传至GitHub,欢迎大 ...

  3. 用C语言制作小型商品信息管理系统过程中的问题

    大神请默默飘过... 以下是第一次制作时的源码: // 商品信息管理.cpp : 定义控制台应用程序的入口点. // // 小型商品信息管理系统.cpp : 定义控制台应用程序的入口点. // #in ...

  4. PHP基础示例:商品信息管理系统v1.1[转]

      实现目标:使用php和mysql写一个商品信息管理系统,并带有购物车功能 一.创建数据库和表 1.创建数据库和表:demodb 2.创建表格:goods 字段:商品编号,商品名称,商品类型,商品图 ...

  5. PHP基础示例:商品信息管理系统v1.1

    实现目标:使用php和mysql写一个商品信息管理系统,并带有购物车功能 一.创建数据库和表 1.创建数据库和表:demodb 2.创建表格:goods 字段:商品编号,商品名称,商品类型,商品图片, ...

  6. Java之从头开始编写简单课程信息管理系统

    编写简单的课程管理系统对于新手并不友好,想要出色的完成并不容易以下是我的一些经验和方法 详情可参考以下链接: https://www.cnblogs.com/dream0-0/p/10090828.h ...

  7. Java课设(学生信息管理系统)

    1.团队课程设计博客链接 http://www.cnblogs.com/Min21/p/7064093.html 2.个人负责模板或任务说明 设计登陆界面和学生信息界面的设计,学生信息的显示.退出等功 ...

  8. 【JAVA】简陋的学生信息管理系统

    因为之前写了一个学生信息管理系统,但还是处于命令行界面,不美观,于是打算做一个完整的界面出来. 在网上查阅资料后发现C++本身是不支持图形化界面的(可以使用第三方的Qt来做) 权衡之下还是选择了JAV ...

  9. java后台设计简单的json数据接口,设置可跨域访问,前端ajax获取json数据

    在开发的过程中,有时候我们需要设计一个数据接口.有时候呢,数据接口和Web服务器又不在一起,所以就有跨域访问的问题. 第一步:简单的设计一个数据接口. 数据接口,听起来高大上,其实呢就是一个简单的Se ...

随机推荐

  1. gitlab基础命令之代码回滚

    #:gitlab状态 root@ubuntu:~# gitlab-ctl status run: alertmanager: (pid 13305) 215965s; run: log: (pid 1 ...

  2. d3基础入门一-选集、数据绑定等核心概念

    引入D3 D3下载,本文下载时的版本为6.5.0 mkdir d3.6.5.0 unzip --help unzip d3.zip -d d3.6.5.0/ ls d3.6.5.0/ API.md C ...

  3. 用Myclipse开发Spring(转)

    原文链接地址是:http://www.cnitblog.com/gavinkin555/articles/35973.html 1 新建一个项目 File----->New ----->P ...

  4. JPA和事务管理

    JPA和事务管理 很重要的一点是JPA本身并不提供任何类型的声明式事务管理.如果在依赖注入容器之外使用JPA,事务处理必须由开发人员编程实现. 123456789101112UserTransacti ...

  5. [BUUCTF]PWN——jarvisoj_test_your_memory

    jarvisoj_test_your_memory 附件 步骤: 例行检查,32位程序,开启了nx保护 试运行一下程序,看看大概的情况 32位ida打开,习惯性的检索程序里的字符串,看到了有关flag ...

  6. HTTP强缓存和协商缓存

    一.浏览器缓存 Web 缓存能够减少延迟与网络阻塞,进而减少显示某个资源所用的时间.借助 HTTP 缓存,Web 站点变得更具有响应性. (一).缓存优点: 减少不必要的数据传输,节省带宽 减少服务器 ...

  7. 资源分配情况(Project)

    <Project2016 企业项目管理实践>张会斌 董方好 编著 资源的分配情况,无非就是未分配.已分配和过度分配三种,这些都可以通过各种视图查看,比如[资源]>[工作组规划器]视图 ...

  8. 批处理文件(.bat)并行Arcpy脚本提高效率的思路

    Arcpy提供数据处理的方便接口,但一个Arcpy脚本通常只运行于一个核上.现在电脑通常是多核乃至多处理器,如果能将任务分解为可同时进行的若干任务,便可通过并行充分利用电脑性能. 折腾了python并 ...

  9. LuoguP2382 化学分子式 题解

    Description 你的任务是编写一个能处理在虚拟的化学里分子式的程序,具体地说,给定你所有原子的相对原子质量,求出所有询问的分子的相对分子质量,或者报告不存在. 数据范围:原子质量 \(\leq ...

  10. Mysql 主从复制机制

    https://blog.csdn.net/girlgolden/article/details/89226528 MySQL异步复制及semi-sync半同步复制,它们都基于MySQL binlog ...