目录
一、系统介绍
1.开发环境
操作系统:Win10
开发工具 :Eclipse2024
JDK版本:jdk1.8
数据库:Mysql8.0
2.技术选型
Java+Swing+Mysql
3.功能模块

4.数据库文件
/*
Navicat Premium Data Transfer
Source Server : mysql
Source Server Type : MySQL
Source Server Version : 80013
Source Host : localhost:3306
Source Schema : swing_property
Target Server Type : MySQL
Target Server Version : 80013
File Encoding : 65001
Date: 17/12/2025 15:37:45
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for building_elec_reading
-- ----------------------------
DROP TABLE IF EXISTS `building_elec_reading`;
CREATE TABLE `building_elec_reading` (
`district_id` double NULL DEFAULT NULL,
`building_id` double NULL DEFAULT NULL,
`date` double NULL DEFAULT 0,
`lift_ele_reading` double NULL DEFAULT NULL,
`lighting_reading` double NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of building_elec_reading
-- ----------------------------
INSERT INTO `building_elec_reading` VALUES (1, 1, 200505, 200504, 200504);
INSERT INTO `building_elec_reading` VALUES (1, 2, 200505, 200504, 200504);
INSERT INTO `building_elec_reading` VALUES (1, 3, 200505, 200504, 200504);
INSERT INTO `building_elec_reading` VALUES (1, 4, 200505, 200504, 200504);
INSERT INTO `building_elec_reading` VALUES (1, 5, 200505, 200504, 200504);
INSERT INTO `building_elec_reading` VALUES (1, 1, 200506, 200505, 200505);
INSERT INTO `building_elec_reading` VALUES (1, 2, 200506, 200505, 200505);
INSERT INTO `building_elec_reading` VALUES (1, 3, 200506, 200505, 200505);
INSERT INTO `building_elec_reading` VALUES (1, 4, 200506, 200505, 200505);
INSERT INTO `building_elec_reading` VALUES (1, 5, 200506, 200505, 200505);
INSERT INTO `building_elec_reading` VALUES (1, 1, 200507, 999999, 999999);
INSERT INTO `building_elec_reading` VALUES (1, 2, 200507, 999999, 999999);
INSERT INTO `building_elec_reading` VALUES (1, 3, 200507, 999999, 999999);
INSERT INTO `building_elec_reading` VALUES (1, 4, 200507, 999999, 999999);
INSERT INTO `building_elec_reading` VALUES (1, 5, 200507, 999999, 999999);
INSERT INTO `building_elec_reading` VALUES (2, 1, 202502, 10, 10);
INSERT INTO `building_elec_reading` VALUES (2, 2, 202502, 10, 10);
INSERT INTO `building_elec_reading` VALUES (2, 3, 202502, 10, 10);
-- ----------------------------
-- Table structure for building_info
-- ----------------------------
DROP TABLE IF EXISTS `building_info`;
CREATE TABLE `building_info` (
`district_id` double NULL DEFAULT NULL,
`building_id` double NULL DEFAULT NULL,
`total_storey` double NULL DEFAULT NULL,
`total_area` double NULL DEFAULT NULL,
`height` double NULL DEFAULT NULL,
`type` double NULL DEFAULT 1,
`status` varchar(9) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '\"use\"'
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of building_info
-- ----------------------------
INSERT INTO `building_info` VALUES (1, 1, 5, 20.3, 60, 1, 'use');
INSERT INTO `building_info` VALUES (1, 2, 5, 20.3, 60, 1, 'use');
INSERT INTO `building_info` VALUES (1, 3, 23, 40.3, 120, 1, 'use');
INSERT INTO `building_info` VALUES (1, 4, 5, 20.3, 60, 1, 'use');
INSERT INTO `building_info` VALUES (1, 5, 5, 20.3, 60, 1, 'use');
INSERT INTO `building_info` VALUES (2, 1, 5, 50, 60, 1, 'use');
INSERT INTO `building_info` VALUES (2, 2, 5, 50, 60, 1, 'use');
INSERT INTO `building_info` VALUES (2, 3, 5, 50, 60, 1, 'use');
INSERT INTO `building_info` VALUES (3, 1, 8, 120, 6, 1, '1');
-- ----------------------------
-- Table structure for district_info
-- ----------------------------
DROP TABLE IF EXISTS `district_info`;
CREATE TABLE `district_info` (
`district_id` int(11) NULL DEFAULT NULL,
`district_name` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`address` varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`floor_space` double NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of district_info
-- ----------------------------
INSERT INTO `district_info` VALUES (2, '圣馨家园', '北京市朝阳区', 2000);
INSERT INTO `district_info` VALUES (3, '澳洲康都', '北京市朝阳区', 6000);
INSERT INTO `district_info` VALUES (4, '华清嘉园', '北京市海淀区', 6000);
INSERT INTO `district_info` VALUES (1, '保利百合', '北京市丰台区', 8000);
-- ----------------------------
-- Table structure for district_reading
-- ----------------------------
DROP TABLE IF EXISTS `district_reading`;
CREATE TABLE `district_reading` (
`district_id` double NULL DEFAULT NULL,
`date` double NULL DEFAULT 0,
`tot_water_reading` double NULL DEFAULT NULL,
`tot_elec_reading` double NULL DEFAULT NULL,
`sec_supply_reading` double NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of district_reading
-- ----------------------------
INSERT INTO `district_reading` VALUES (1, 200505, 200504, 200504, 200504);
INSERT INTO `district_reading` VALUES (1, 200506, 200505, 200505, 200505);
INSERT INTO `district_reading` VALUES (1, 200507, 999999, 999999, 999999);
INSERT INTO `district_reading` VALUES (1, 201901, 354, 345, 4567);
INSERT INTO `district_reading` VALUES (2, 202502, 30, 30, 30);
-- ----------------------------
-- Table structure for emp_info
-- ----------------------------
DROP TABLE IF EXISTS `emp_info`;
CREATE TABLE `emp_info` (
`uname` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`ename` varchar(9) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`dept` varchar(9) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`duty` varchar(9) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`office_phone` double NULL DEFAULT NULL,
`emp_date` datetime(0) NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of emp_info
-- ----------------------------
INSERT INTO `emp_info` VALUES ('admin', '李四', '系统管理', '经理', 13959264312, '2019-09-01 00:00:00');
INSERT INTO `emp_info` VALUES ('pahran', '张三', '软件学院', '学生', 5922101227, '2019-09-02 00:00:00');
-- ----------------------------
-- Table structure for login_info
-- ----------------------------
DROP TABLE IF EXISTS `login_info`;
CREATE TABLE `login_info` (
`uname` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`paswrd` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`purview` double NULL DEFAULT 0
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of login_info
-- ----------------------------
INSERT INTO `login_info` VALUES ('superadmin', '123456', 2);
INSERT INTO `login_info` VALUES ('user', '123456', 0);
INSERT INTO `login_info` VALUES ('admin', '123456', 1);
-- ----------------------------
-- Table structure for paying_charge
-- ----------------------------
DROP TABLE IF EXISTS `paying_charge`;
CREATE TABLE `paying_charge` (
`district_id` double NULL DEFAULT NULL,
`building_id` double NULL DEFAULT NULL,
`room_id` double NULL DEFAULT NULL,
`date` datetime(0) NULL DEFAULT NULL,
`deadline` datetime(0) NULL DEFAULT NULL,
`totoal_fee` double NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of paying_charge
-- ----------------------------
-- ----------------------------
-- Table structure for room_info
-- ----------------------------
DROP TABLE IF EXISTS `room_info`;
CREATE TABLE `room_info` (
`district_id` int(11) NULL DEFAULT NULL,
`building_id` int(11) NULL DEFAULT NULL,
`room_id` int(11) NULL DEFAULT NULL,
`area` double NULL DEFAULT NULL,
`status` varchar(9) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '\"use\"',
`purpose` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '\"resident\"',
`oname` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sex` varchar(7) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`id_num` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`address` varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`phone` varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of room_info
-- ----------------------------
INSERT INTO `room_info` VALUES (1, 1, 101, 120, 'use', 'resident', '李四', '男', '622425200512123212', '甘肃省定西市陇西县巩昌镇', '1222586956');
INSERT INTO `room_info` VALUES (1, 1, 102, 120, 'use', 'resident', '王五', '男', '622425200512123212', '甘肃省定西市陇西县巩昌镇', '1222586956');
INSERT INTO `room_info` VALUES (1, 1, 103, 120, 'use', 'resident', '赵六', '男', '622425200512123212', '甘肃省定西市陇西县巩昌镇', '1222586956');
INSERT INTO `room_info` VALUES (1, 1, 201, 140, 'use', 'resident', '柳七', '男', '622425200512123212', '甘肃省定西市陇西县巩昌镇', '1222586956');
INSERT INTO `room_info` VALUES (1, 1, 202, 140, 'use', 'resident', '韩七', '男', '622425200512123212', '甘肃省定西市陇西县巩昌镇', '1222586956');
INSERT INTO `room_info` VALUES (1, 1, 203, 140, 'use', 'resident', '曹九', '女', '622425200512123212', '甘肃省定西市陇西县巩昌镇', '1222586956');
INSERT INTO `room_info` VALUES (1, 1, 301, 100, '\"use\"', '\"resident\"', '张丽', '女', '622425200512123212', '甘肃省定西市陇西县文峰镇', '6655321');
INSERT INTO `room_info` VALUES (1, 1, 302, 100, '\"use\"', '\"resident\"', '张花', '女', '622425200512123212', '甘肃省定西市陇西县文峰镇', '6655321');
INSERT INTO `room_info` VALUES (1, 2, 101, 150, '\"use\"', '\"resident\"', '张三', '男', '622425200512123212', '甘肃省定西市陇西县', '1513255237');
INSERT INTO `room_info` VALUES (1, 2, 102, 150, '\"use\"', '\"resident\"', '李华', '男', '622425200512123212', '甘肃省定西市陇西县文峰镇', '6655321');
INSERT INTO `room_info` VALUES (1, 2, 103, 150, '\"use\"', '\"resident\"', '李丽', '女', '622425200512123212', '甘肃省定西市陇西县文峰镇', '6655321');
INSERT INTO `room_info` VALUES (2, 1, 101, 160, '\"use\"', '\"resident\"', '张三', '男', '110105200212123653', '北京市朝阳区', '1001232');
INSERT INTO `room_info` VALUES (2, 1, 102, 160, '\"use\"', '\"resident\"', '张丽', '女', '110105200212123653', '北京市朝阳区', '1001232');
-- ----------------------------
-- Table structure for unit_price_info
-- ----------------------------
DROP TABLE IF EXISTS `unit_price_info`;
CREATE TABLE `unit_price_info` (
`charge_id` int(11) NULL DEFAULT NULL,
`charge_name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`unit_price` double NULL DEFAULT 0
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of unit_price_info
-- ----------------------------
INSERT INTO `unit_price_info` VALUES (2, '电费', 2);
INSERT INTO `unit_price_info` VALUES (3, '暖气费', 4);
INSERT INTO `unit_price_info` VALUES (4, '燃气费', 5);
INSERT INTO `unit_price_info` VALUES (1, '电费', 2);
-- ----------------------------
-- Table structure for user_reading
-- ----------------------------
DROP TABLE IF EXISTS `user_reading`;
CREATE TABLE `user_reading` (
`district_id` double NULL DEFAULT NULL,
`building_id` double NULL DEFAULT NULL,
`room_id` double NULL DEFAULT NULL,
`date` double NULL DEFAULT 0,
`water_reading` double NULL DEFAULT NULL,
`elec_reading` double NULL DEFAULT NULL,
`gas_reading` double NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of user_reading
-- ----------------------------
INSERT INTO `user_reading` VALUES (1, 1, 101, 202009, 12, 234, 132);
INSERT INTO `user_reading` VALUES (1, 1, 102, 202009, 234, 234, 234);
INSERT INTO `user_reading` VALUES (1, 1, 103, 202009, 5364, 234, 234);
INSERT INTO `user_reading` VALUES (1, 1, 201, 202009, 234, 234, 243);
INSERT INTO `user_reading` VALUES (1, 1, 202, 202009, 456, 4235, 345);
INSERT INTO `user_reading` VALUES (1, 1, 203, 202009, 4567, 534, 345);
INSERT INTO `user_reading` VALUES (1, 1, 101, 202008, 234, 3245, 3465);
INSERT INTO `user_reading` VALUES (1, 1, 102, 202008, 435, 235, 2345);
INSERT INTO `user_reading` VALUES (1, 1, 103, 202008, 342, 6435, 2354);
INSERT INTO `user_reading` VALUES (1, 1, 201, 202008, 2345, 234, 2345);
INSERT INTO `user_reading` VALUES (1, 1, 202, 202008, 2345, 3645, 4365);
INSERT INTO `user_reading` VALUES (1, 1, 203, 202008, 7654, 234, 12435);
INSERT INTO `user_reading` VALUES (2, 1, 101, 202502, 10, 10, 10);
INSERT INTO `user_reading` VALUES (2, 1, 102, 202502, 20, 20, 20);
INSERT INTO `user_reading` VALUES (2, 1, 101, 202503, 12, 12, 12);
INSERT INTO `user_reading` VALUES (2, 1, 102, 202503, 13, 13, 13);
SET FOREIGN_KEY_CHECKS = 1;
5.工程结构

二、系统展示
1.登录系统

2.系统首页

3.小区信息维护

4.楼宇信息维护

5.房屋信息维护

6.修改收费单价

7.显示收费单价

8.业主数据录入


9.公共数据录入


10.按照业主查询


11.按照楼宇查询


12.按照小区查询


三、部分代码
1.登录系统
package com.sjsq;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
/**
*
* 登录界面
* @author 水坚石青
*
*/
public class LoginFrame extends JFrame {
private JLabel nameLabel, passwordLabel, pictureLabel;// 标签
private JButton okButton, cancelButton, helpButton;// 按钮
private JTextField nameText, passText;// 文本框
private static JPasswordField passField;// 密码框
private JPanel buttonPanel, fieldPanel1, fieldPanel2, fieldPanel;// 容器
private static Connection connection;//
private PreparedStatement statement;
private String user, pwd;
private static boolean found = false;
private static LoginFrame login;
public LoginFrame() {
super("物业管理系统");
Container con = getContentPane();
con.setLayout(new BorderLayout());
nameLabel = new JLabel("账号:");
nameText = new JTextField("", 10);
fieldPanel1 = new JPanel();
fieldPanel1.setLayout(new FlowLayout());
fieldPanel1.add(nameLabel);
fieldPanel1.add(nameText);
passwordLabel = new JLabel("密码:");
passField = new JPasswordField(10);
fieldPanel2 = new JPanel();
fieldPanel2.setLayout(new FlowLayout());
fieldPanel2.add(passwordLabel);
fieldPanel2.add(passField);
fieldPanel = new JPanel();
fieldPanel.setLayout(new BorderLayout());
fieldPanel.add(fieldPanel1,BorderLayout.NORTH);
fieldPanel.add(fieldPanel2,BorderLayout.SOUTH);
okButton = new JButton("确定");
okButton.addActionListener(new LoginCheck());
cancelButton = new JButton("取消");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
});
helpButton = new JButton("帮助");
buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
buttonPanel.add(helpButton);
Icon bug = new ImageIcon("1.gif");
pictureLabel = new JLabel(bug);
con.add(pictureLabel);
con.add(fieldPanel, BorderLayout.NORTH);
con.add(buttonPanel, BorderLayout.SOUTH);
}
public static void changeUser() {
login.setVisible(true);
passField.setText("");
found = false;
}
public static Connection getConn() {
return connection;
}
public static void main(String args[]) {
login = new LoginFrame();
login.setSize(350, 150);
login.setResizable(false);
login.setVisible(true);
login.setLocationRelativeTo(null);
login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class LoginCheck implements ActionListener {
public void actionPerformed(ActionEvent event) {
user = nameText.getText();
pwd = new String(passField.getPassword());
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC", "root",
"admin");
String sql = "select * from login_info";
statement = connection.prepareStatement(sql);
ResultSet result = statement.executeQuery();
while (result.next()) {
if (user.compareTo(result.getString("" + "" + "uname")) == 0
&& pwd.compareTo(result.getString("paswrd")) == 0) {
MainFrame.setCurtentuser(user);
System.out.println(user + ":" + pwd);
found = true;
MainFrame.mainFrame(user, result.getInt("purview"));
LoginFrame.this.setVisible(false);
}
}
if (!found) {
JOptionPane.showMessageDialog(null, "用户名或密码错误,请重输", "错误", JOptionPane.ERROR_MESSAGE);
nameText.setText("");
passField.setText("");
}
result.close();
statement.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
2.小区信息维护
package com.sjsq;
import javax.swing.table.AbstractTableModel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
/**
* 小区信息维护
* @author 水坚石青
*
*/
public class CommunityInfoFrame extends JFrame {
private JPanel buttonPanel, tablePanel, fieldPanel, fieldPanel1;
private JLabel label1 = new JLabel();
private JTextField districtid = new JTextField(3);
private JLabel label2 = new JLabel();
private JTextField buildingid = new JTextField(6);
private JLabel label3 = new JLabel();
private JTextField stac = new JTextField(7);
private JLabel label4 = new JLabel();
private JTextField func = new JTextField(5);
private JButton addButton = new JButton("添加");
private JButton changeButton = new JButton("修改");
private JButton deleteButton = new JButton("删除");
private JButton renewButton = new JButton("重置");
private JButton updateButton = new JButton("更新");
String title[] = { "小区编号", "小区名称", "小区地址", "占地面积" };
Vector vector = new Vector();
Connection connection = null;
ResultSet rSet = null;
Statement statement = null;
AbstractTableModel tm;
public CommunityInfoFrame() {
super("小区信息维护");
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
} catch (SQLException e) {
e.printStackTrace();
}
}
private void jbInit() throws SQLException {
Container con = getContentPane();
con.setLayout(new BorderLayout());
label1.setText("小区编号");
label2.setText("小区名称");
label3.setText("小区地址");
label4.setText("占地面积");
// 设置监听
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addButton_actionPerformed(e);
}
});
changeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeButton_actionPerformed(e);
}
});
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deleteButton_actionPerformed(e);
}
});
renewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
renewButton_actionPerformed(e);
}
});
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateButton_actionPerformed(e);
}
});
fieldPanel1 = new JPanel();
fieldPanel1.setLayout(new FlowLayout());
fieldPanel1.add(label1);
fieldPanel1.add(districtid);
fieldPanel1.add(label2);
fieldPanel1.add(buildingid);
fieldPanel1.add(label3);
fieldPanel1.add(stac);
fieldPanel1.add(label4);
fieldPanel1.add(func);
fieldPanel = new JPanel();
fieldPanel.setLayout(new FlowLayout());
fieldPanel.add(fieldPanel1);
buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(addButton);
buttonPanel.add(changeButton);
buttonPanel.add(deleteButton);
buttonPanel.add(renewButton);
buttonPanel.add(updateButton);
tablePanel = new JPanel();
createtable();
con.add(tablePanel, BorderLayout.NORTH);
con.add(fieldPanel, BorderLayout.CENTER);
con.add(buttonPanel, BorderLayout.SOUTH);
updated();
setSize(600, 600);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
CommunityInfoFrame XiaoQuinformation = new CommunityInfoFrame();
XiaoQuinformation.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void createtable() {
JTable table;
JScrollPane scroll;
tm = new AbstractTableModel() {
public int getColumnCount() {
return title.length;
}
public int getRowCount() {
return vector.size();
}
public String getColumnName(int col) {
return title[col];
}
public Object getValueAt(int row, int column) {
if (!vector.isEmpty()) {
return ((Vector) vector.elementAt(row)).elementAt(column);
} else {
return null;
}
}
public void setValueAt(Object value, int row, int column) {
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int column) {
return false;
}
};
table = new JTable(tm);
table.setToolTipText("Display Query Result");
table.setAutoResizeMode(table.AUTO_RESIZE_OFF);
table.setCellSelectionEnabled(false);
table.setShowHorizontalLines(true);
table.setShowVerticalLines(true);
scroll = new JScrollPane(table);
scroll.setBounds(6, 20, 540, 250);
tablePanel.add(scroll);
}
void addButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql1 = "insert into district_info(district_id,district_name,address,floor_space) values("
+ Integer.parseInt(districtid.getText()) + ",'" + buildingid.getText() + "','" + stac.getText()
+ "'," + Integer.parseInt(func.getText()) + ")";
statement.executeUpdate(sql1);
} catch (Exception ex) {
JOptionPane.showMessageDialog(CommunityInfoFrame.this, "填加数据出错", "错误", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLSQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
updated();
}
void changeButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql1 = "update district_info set district_id=" + Integer.parseInt(districtid.getText())
+ ",district_name='" + buildingid.getText() + "',address='" + stac.getText() + "',floor_space="
+ Integer.parseInt(func.getText()) + " WHERE district_id=" + Integer.parseInt(districtid.getText());
statement.executeUpdate(sql1);
} catch (Exception ex) {
JOptionPane.showMessageDialog(CommunityInfoFrame.this, "修改数据出错,注意所填写的数据是否正确!", "错误", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLSQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
updated();
}
void deleteButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql2 = "delete from district_info where district_id=" + Integer.parseInt(districtid.getText());
statement.executeUpdate(sql2);
} catch (Exception ex) {
JOptionPane.showMessageDialog(CommunityInfoFrame.this, "删除数据出错,注意小区号是否正确!", "错误", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLSQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
updated();
}
void updateButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql3 = "select * from district_info";
rSet = statement.executeQuery(sql3);
if (rSet.next() == false) {
JOptionPane.showMessageDialog(CommunityInfoFrame.this, "数据库无相应内容", "错误", JOptionPane.ERROR_MESSAGE);
} else {
String sql = "select * from district_info";
ResultSet rs = statement.executeQuery(sql);
districtid.setText("");
buildingid.setText("");
stac.setText("");
func.setText("");
vector.removeAllElements();
tm.fireTableStructureChanged();
while (rs.next()) {
Vector rec_vector = new Vector();
rec_vector.addElement(String.valueOf(rs.getInt(1)));
rec_vector.addElement(String.valueOf(rs.getInt(2)));
rec_vector.addElement(String.valueOf(rs.getInt(3)));
rec_vector.addElement(String.valueOf(rs.getInt(4)));
vector.addElement(rec_vector);
}
tm.fireTableStructureChanged();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLSQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
}
void updated() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql3 = "select * from district_info";
rSet = statement.executeQuery(sql3);
if (rSet.next() == true) {
String sql = "select * from district_info";
ResultSet rs = statement.executeQuery(sql);
vector.removeAllElements();
tm.fireTableStructureChanged();
while (rs.next()) {
Vector rec_vector = new Vector();
rec_vector.addElement(rs.getString(1));
rec_vector.addElement(rs.getString(2));
rec_vector.addElement(rs.getString(3));
rec_vector.addElement(rs.getString(4));
vector.addElement(rec_vector);
}
tm.fireTableStructureChanged();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLSQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
}
void renewButton_actionPerformed(ActionEvent e) {
districtid.setText("");
buildingid.setText("");
stac.setText("");
func.setText("");
}
}
3.楼宇信息维护
package com.sjsq;
import javax.swing.table.AbstractTableModel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.sql.*;
import java.util.*;
/**
* 楼宇信息维护
* @author 水坚石青
*
*/
public class BulidingInfoFrame extends JFrame {
private JPanel buttonPanel, tablePanel, fieldPanel, fieldPanel1, fieldPanel2;
private JLabel label1 = new JLabel();
private JTextField districtid = new JTextField(3);
private JLabel label2 = new JLabel();
private JTextField buildingid = new JTextField(3);
private JLabel label3 = new JLabel();
private JTextField storey = new JTextField(4);
private JLabel label4 = new JLabel();
private JTextField area = new JTextField(4);
private JLabel label5 = new JLabel();
private JTextField height = new JTextField(4);
private JLabel label6 = new JLabel();
private JTextField type = new JTextField(5);
private JLabel label7 = new JLabel();
private JTextField state = new JTextField(6);
private JButton searchButton = new JButton("按小区查询");
private JButton addButton = new JButton("添加");
private JButton changeButton = new JButton("修改");
private JButton deleteButton = new JButton("删除");
private JButton renewButton = new JButton("重置");
private JButton updateButton = new JButton("更新");
String title[] = { "小区编号", "楼宇编号", "楼宇层数", "产权面积", "楼宇高度", "类型", "楼宇状态" };
Vector vector = new Vector();
Connection connection = null;
ResultSet rSet = null;
Statement statement = null;
AbstractTableModel tm;
public BulidingInfoFrame() {
super("楼宇信息维护");
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
Container con = getContentPane();
con.setLayout(new BorderLayout());
label1.setText("小区编号");
label2.setText("楼宇编号");
label3.setText("楼宇层数");
label4.setText("产权面积");
label5.setText("楼宇高度");
label6.setText("类型");
label7.setText("楼宇状态");
searchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
searchButton_actionPerformed(e);
}
});
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addButton_actionPerformed(e);
}
});
changeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeButton_actionPerformed(e);
}
});
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deleteButton_actionPerformed(e);
}
});
renewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
renewButton_actionPerformed(e);
}
});
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateButton_actionPerformed(e);
}
});
fieldPanel1 = new JPanel();
fieldPanel1.setLayout(new FlowLayout());
fieldPanel1.add(label1);
fieldPanel1.add(districtid);
fieldPanel1.add(label2);
fieldPanel1.add(buildingid);
fieldPanel1.add(label3);
fieldPanel1.add(storey);
fieldPanel1.add(label4);
fieldPanel1.add(area);
fieldPanel2 = new JPanel();
fieldPanel2.setLayout(new FlowLayout());
fieldPanel2.add(label5);
fieldPanel2.add(height);
fieldPanel2.add(label6);
fieldPanel2.add(type);
fieldPanel2.add(label7);
fieldPanel2.add(state);
fieldPanel = new JPanel();
fieldPanel.setLayout(new BorderLayout());
fieldPanel.add(fieldPanel1, BorderLayout.NORTH);
fieldPanel.add(fieldPanel2, BorderLayout.CENTER);
buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(searchButton);
buttonPanel.add(addButton);
buttonPanel.add(changeButton);
buttonPanel.add(deleteButton);
buttonPanel.add(renewButton);
buttonPanel.add(updateButton);
tablePanel = new JPanel();
createtable();
con.add(tablePanel, BorderLayout.NORTH);
con.add(fieldPanel, BorderLayout.CENTER);
con.add(buttonPanel, BorderLayout.SOUTH);
updated();
setSize(600, 650);
setResizable(false);
setVisible(true);
setLocationRelativeTo(null);
}
public static void main(String[] args) {
BulidingInfoFrame userInformation = new BulidingInfoFrame();
userInformation.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void createtable() {
JTable table;
JScrollPane scroll;
tm = new AbstractTableModel() {
public int getColumnCount() {
return title.length;
}
public int getRowCount() {
return vector.size();
}
public String getColumnName(int col) {
return title[col];
}
public Object getValueAt(int row, int column) {
if (!vector.isEmpty()) {
return ((Vector) vector.elementAt(row)).elementAt(column);
} else {
return null;
}
}
public void setValueAt(Object value, int row, int column) {
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int column) {
return false;
}
};
table = new JTable(tm);
table.setToolTipText("Display Query Result");
table.setAutoResizeMode(table.AUTO_RESIZE_OFF);
table.setCellSelectionEnabled(false);
table.setShowHorizontalLines(true);
table.setShowVerticalLines(true);
scroll = new JScrollPane(table);
scroll.setBounds(6, 20, 540, 250);
tablePanel.add(scroll);
}
void addButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql1 = "insert into building_info(district_id,building_id,total_storey,total_area,height,type,status) values("
+ Integer.parseInt(districtid.getText()) + "," + Integer.parseInt(buildingid.getText()) + ","
+ Integer.parseInt(storey.getText()) + "," + Integer.parseInt(area.getText()) + ","
+ Integer.parseInt(height.getText()) + "," + Integer.parseInt(type.getText()) + ",'"
+ state.getText() + "')";
statement.executeUpdate(sql1);
} catch (Exception ex) {
JOptionPane.showMessageDialog(BulidingInfoFrame.this, "填加数据出错", "错误", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
updated();
}
void changeButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql1 = "update building_info set diatrict_id=" + Integer.parseInt(districtid.getText())
+ ",buildingid=" + Integer.parseInt(buildingid.getText()) + ",total_storey='"
+ Integer.parseInt(storey.getText()) + ",total_area=" + Integer.parseInt(area.getText())
+ ",height=" + Integer.parseInt(height.getText()) + ",type=" + Integer.parseInt(type.getText())
+ ",status='" + state.getText() + "' WHERE district_id=" + Integer.parseInt(districtid.getText())
+ " AND building_id=" + Integer.parseInt(buildingid.getText());
statement.executeUpdate(sql1);
} catch (Exception ex) {
JOptionPane.showMessageDialog(BulidingInfoFrame.this, "修改数据出错,注意小区号和楼号是否正确!", "错误", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
updated();
}
void deleteButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql2 = "delete from building_info where district_id=" + Integer.parseInt(districtid.getText())
+ "AND building_id=" + Integer.parseInt(buildingid.getText());
statement.executeUpdate(sql2);
} catch (Exception ex) {
JOptionPane.showMessageDialog(BulidingInfoFrame.this, "输入的数据有误,无法执行删除,注意小区编号和楼宇编号是否正确!", "错误",
JOptionPane.ERROR_MESSAGE);
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
updated();
}
void updateButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql3 = "select * from building_info";
rSet = statement.executeQuery(sql3);
if (rSet.next() == false) {
JOptionPane.showMessageDialog(BulidingInfoFrame.this, "数据库无相应内容", "错误", JOptionPane.ERROR_MESSAGE);
} else {
String sql = "select * from building_info";
ResultSet rs = statement.executeQuery(sql);
districtid.setText("");
buildingid.setText("");
storey.setText("");
area.setText("");
height.setText("");
type.setText("");
state.setText("");
vector.removeAllElements();
tm.fireTableStructureChanged();
while (rs.next()) {
Vector rec_vector = new Vector();
rec_vector.addElement(String.valueOf(rs.getInt(1)));
rec_vector.addElement(String.valueOf(rs.getInt(2)));
rec_vector.addElement(String.valueOf(rs.getInt(3)));
rec_vector.addElement(String.valueOf(rs.getInt(4)));
rec_vector.addElement(rs.getString(5));
rec_vector.addElement(rs.getString(6));
rec_vector.addElement(rs.getString(7));
vector.addElement(rec_vector);
}
tm.fireTableStructureChanged();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
}
void searchButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql4 = "select * from building_info where district_id=" + Integer.parseInt(districtid.getText());
rSet = statement.executeQuery(sql4);
if (rSet.next() == false) {
JOptionPane msg = new JOptionPane();
JOptionPane.showMessageDialog(BulidingInfoFrame.this, "数据库无相应内容", "错误", JOptionPane.ERROR_MESSAGE);
vector.removeAllElements();
tm.fireTableStructureChanged();
} else {
String sqll = "select * from building_info where district_id=" + Integer.parseInt(districtid.getText());
ResultSet rs = statement.executeQuery(sqll);
vector.removeAllElements();
tm.fireTableStructureChanged();
while (rs.next()) {
Vector rec_vector = new Vector();
rec_vector.addElement(String.valueOf(rs.getInt(1)));
rec_vector.addElement(String.valueOf(rs.getInt(2)));
rec_vector.addElement(String.valueOf(rs.getInt(3)));
rec_vector.addElement(String.valueOf(rs.getInt(4)));
rec_vector.addElement(rs.getString(5));
rec_vector.addElement(rs.getString(6));
rec_vector.addElement(rs.getString(7));
vector.addElement(rec_vector);
}
tm.fireTableStructureChanged();
}
}
catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
}
void updated() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql3 = "select * from building_info";
rSet = statement.executeQuery(sql3);
if (rSet.next() == true) {
String sql = "select * from building_info";
ResultSet rs = statement.executeQuery(sql);
vector.removeAllElements();
tm.fireTableStructureChanged();
while (rs.next()) {
Vector rec_vector = new Vector();
rec_vector.addElement(String.valueOf(rs.getInt(1)));
rec_vector.addElement(String.valueOf(rs.getInt(2)));
rec_vector.addElement(String.valueOf(rs.getInt(3)));
rec_vector.addElement(String.valueOf(rs.getInt(4)));
rec_vector.addElement(rs.getString(5));
rec_vector.addElement(rs.getString(6));
rec_vector.addElement(rs.getString(7));
vector.addElement(rec_vector);
}
tm.fireTableStructureChanged();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
}
void renewButton_actionPerformed(ActionEvent e) {
districtid.setText("");
buildingid.setText("");
storey.setText("");
area.setText("");
height.setText("");
type.setText("");
state.setText("");
}
}
4.房屋信息维护
package com.sjsq;
import javax.swing.table.AbstractTableModel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
/**
* 房屋信息维护
* @author 水坚石青
*
*/
public class HouseInfoFrame extends JFrame {
private JPanel buttonPanel, tablePanel, fieldPanel, fieldPanel1, fieldPanel2, fieldPanel3;
private JLabel label1 = new JLabel();
private JTextField districtid = new JTextField(6);
private JLabel label2 = new JLabel();
private JTextField buildingid = new JTextField(3);
private JLabel label3 = new JLabel();
private JTextField roomid = new JTextField(4);
private JLabel label4 = new JLabel();
private JTextField area = new JTextField(5);
private JLabel label5 = new JLabel();
private JTextField stac = new JTextField(5);
private JLabel label6 = new JLabel();
private JTextField func = new JTextField(5);
private JLabel label7 = new JLabel();
private JTextField ownername = new JTextField(6);
private JLabel label8 = new JLabel();
private JTextField sex = new JTextField(4);
private JLabel label9 = new JLabel();
private JTextField idnum = new JTextField(13);
private JLabel label10 = new JLabel();
private JTextField addr = new JTextField(15);
private JLabel label11 = new JLabel();
private JTextField tetel = new JTextField(8);
private JButton searchButton = new JButton("姓名查询");
private JButton addButton = new JButton("添加");
private JButton changeButton = new JButton("修改");
private JButton deleteButton = new JButton("删除");
private JButton renewButton = new JButton("重置");
private JButton updateButton = new JButton("更新");
String title[] = { "小区号", "楼号", "房号", "产权面积", "房屋状态", "用途", "业主姓名", "性别", "身份证", "联系地址", "联系电话" };
Vector vector = new Vector();
Connection connection = null;
ResultSet rSet = null;
Statement statement = null;
AbstractTableModel tm;
public HouseInfoFrame() {
super("房屋信息维护");
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
setSize(1000, 680);
setResizable(false);
setVisible(true);
setLocationRelativeTo(null);
}
private void jbInit() throws Exception {
Container con = getContentPane();
con.setLayout(new BorderLayout());
label1.setText("小区");
label2.setText("楼号");
label3.setText("房号");
label4.setText("产权面积");
label5.setText("房屋状态");
label6.setText("用途");
label7.setText("姓名");
label8.setText("性别");
label9.setText("身份证");
label10.setText("联系地址");
label11.setText("联系电话");
searchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
searchButton_actionPerformed(e);
}
});
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addButton_actionPerformed(e);
}
});
changeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeButton_actionPerformed(e);
}
});
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deleteButton_actionPerformed(e);
}
});
renewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
renewButton_actionPerformed(e);
}
});
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateButton_actionPerformed(e);
}
});
fieldPanel1 = new JPanel();
fieldPanel1.setLayout(new FlowLayout());
fieldPanel1.add(label1);
fieldPanel1.add(districtid);
fieldPanel1.add(label2);
fieldPanel1.add(buildingid);
fieldPanel1.add(label3);
fieldPanel1.add(roomid);
fieldPanel1.add(label4);
fieldPanel1.add(area);
fieldPanel2 = new JPanel();
fieldPanel2.setLayout(new FlowLayout());
// fieldPanel2.add(label5);
// fieldPanel2.add(stac);
// fieldPanel2.add(label6);
// fieldPanel2.add(func);
fieldPanel2.add(label7);
fieldPanel2.add(ownername);
fieldPanel2.add(label8);
fieldPanel2.add(sex);
fieldPanel2.add(label9);
fieldPanel2.add(idnum);
fieldPanel3 = new JPanel();
fieldPanel3.setLayout(new FlowLayout());
fieldPanel3.add(label10);
fieldPanel3.add(addr);
fieldPanel3.add(label11);
fieldPanel3.add(tetel);
fieldPanel = new JPanel();
fieldPanel.setLayout(new BorderLayout());
fieldPanel.add(fieldPanel1, BorderLayout.NORTH);
fieldPanel.add(fieldPanel2, BorderLayout.CENTER);
fieldPanel.add(fieldPanel3, BorderLayout.SOUTH);
buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(searchButton);
buttonPanel.add(addButton);
buttonPanel.add(changeButton);
buttonPanel.add(deleteButton);
buttonPanel.add(renewButton);
buttonPanel.add(updateButton);
tablePanel = new JPanel();
createtable();
con.add(tablePanel, BorderLayout.NORTH);
con.add(fieldPanel, BorderLayout.CENTER);
con.add(buttonPanel, BorderLayout.SOUTH);
updated();
}
private void createtable() {
JTable table;
JScrollPane scroll;
// vector = new Vector();
tm = new AbstractTableModel() {
public int getColumnCount() {
return title.length;
}
public int getRowCount() {
return vector.size();
}
public String getColumnName(int col) {
return title[col];
}
public Object getValueAt(int row, int column) {
if (!vector.isEmpty()) {
return ((Vector) vector.elementAt(row)).elementAt(column);
} else {
return null;
}
}
public void setValueAt(Object value, int row, int column) {
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int column) {
return false;
}
};
table = new JTable(tm);
table.setToolTipText("Display Query Result");
// 设置表格的尺寸
table.setPreferredScrollableViewportSize(new Dimension(825, 400)); // 更改为所需的宽度和高度
table.setSize(1000,600);
table.setAutoResizeMode(table.AUTO_RESIZE_OFF);
table.setCellSelectionEnabled(false);
table.setShowHorizontalLines(true);
table.setShowVerticalLines(true);
scroll = new JScrollPane(table);
scroll.setBounds(1000, 500, 1000, 500);
tablePanel.add(scroll);
}
void addButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql1 = "insert into room_info(district_id,building_id,room_id,area,oname,sex,id_num,address,phone) values("
+ Integer.parseInt(districtid.getText()) + "," + Integer.parseInt(buildingid.getText()) + ","
+ Integer.parseInt(roomid.getText()) + "," + Integer.parseInt(area.getText()) + ",'"
+ ownername.getText() + "','" + sex.getText() + "','" + idnum.getText() + "','" + addr.getText()
+ "'," + Integer.parseInt(tetel.getText()) + ")";
statement.executeUpdate(sql1);
} catch (Exception ex) {
JOptionPane.showMessageDialog(HouseInfoFrame.this, "填加数据出错", "错误", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
updated();
}
// 修改房屋信息
void changeButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql1 = "update room_info set area=" + Integer.parseInt(area.getText()) + ",oname='"
+ ownername.getText() + "',sex='" + sex.getText() + "',id_num='" + idnum.getText() + "',address='"
+ addr.getText() + "',phone=" + Integer.parseInt(tetel.getText()) + " WHERE district_id="
+ Integer.parseInt(districtid.getText()) + " AND building_id="
+ Integer.parseInt(buildingid.getText()) + " AND room_id=" + Integer.parseInt(roomid.getText());
statement.executeUpdate(sql1);
} catch (Exception ex) {
JOptionPane.showMessageDialog(HouseInfoFrame.this, "修改数据出错,注意所填写的数据是否正确!", "错误", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
updated();
}
// 删除房屋信息
void deleteButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql2 = "delete from room_info where district_id=" + Integer.parseInt(districtid.getText())
+ " AND building_id=" + Integer.parseInt(buildingid.getText()) + " AND room_id="
+ Integer.parseInt(roomid.getText());// +"area="+Integer.parseInt(area.getText())+"||oname="+ownername.getText()+"||sex="+sex.getText()+"||id_num="+idnum.getText()+"||address="+addr.getText()+"||phone="+Integer.parseInt(tetel.getText());
System.out.println("删除房屋信息语句:"+sql2);
statement.executeUpdate(sql2);
} catch (Exception ex) {
JOptionPane.showMessageDialog(HouseInfoFrame.this, "删除数据出错,注意小区号,楼号,房间号是否正确!", "错误", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
updated();
}
void updateButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql3 = "select * from room_info";
rSet = statement.executeQuery(sql3);
if (rSet.next() == false) {
// JOptionPane msg= new JOptionPane();
JOptionPane.showMessageDialog(HouseInfoFrame.this, "数据库无相应内容", "错误", JOptionPane.ERROR_MESSAGE);
} else {
String sql = "select * from room_info";
ResultSet rs = statement.executeQuery(sql);
districtid.setText("");
buildingid.setText("");
roomid.setText("");
area.setText("");
ownername.setText("");
sex.setText("");
idnum.setText("");
addr.setText("");
tetel.setText("");
vector.removeAllElements();
tm.fireTableStructureChanged();
while (rs.next()) {
Vector rec_vector = new Vector();
rec_vector.addElement(String.valueOf(rs.getInt(1)));
rec_vector.addElement(String.valueOf(rs.getInt(2)));
rec_vector.addElement(String.valueOf(rs.getInt(3)));
rec_vector.addElement(String.valueOf(rs.getInt(4)));
rec_vector.addElement(rs.getString(5));
rec_vector.addElement(rs.getString(6));
rec_vector.addElement(rs.getString(7));
rec_vector.addElement(rs.getString(8));
rec_vector.addElement(rs.getString(9));
rec_vector.addElement(rs.getString(10));
rec_vector.addElement(String.valueOf(rs.getInt(11)));
vector.addElement(rec_vector);
}
tm.fireTableStructureChanged();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
}
void searchButton_actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
// String sql4= "select * from room_info where
// district_id="+Integer.parseInt(districtid.getText())+"||building_id="+Integer.parseInt(buildingid.getText())+"||room_id="+Integer.parseInt(roomid.getText())+"area="+Integer.parseInt(area.getText())+"||oname='"+ownername.getText()+"'||sex='"+sex.getText()+"'||id_num="+idnum.getText()+"||address="+addr.getText()+"||phone="+Integer.parseInt(tetel.getText());
String sql4 = "select * from room_info where oname='" + ownername.getText() + "'";
rSet = statement.executeQuery(sql4);
if (rSet.next() == false) {
JOptionPane msg = new JOptionPane();
JOptionPane.showMessageDialog(HouseInfoFrame.this, "数据库无相应内容", "错误", JOptionPane.ERROR_MESSAGE);
vector.removeAllElements();
tm.fireTableStructureChanged();
} else {
// String sqll= "select * from room_info where
// district_id="+Integer.parseInt(districtid.getText())+"||building_id="+Integer.parseInt(buildingid.getText())+"||room_id="+Integer.parseInt(roomid.getText())+"area="+Integer.parseInt(area.getText())+"||oname='"+ownername.getText()+"'||sex='"+sex.getText()+"'||id_num="+idnum.getText()+"||address="+addr.getText()+"||phone="+Integer.parseInt(tetel.getText());
String sqll = "select * from room_info where oname='" + ownername.getText() + "'";
ResultSet rs = statement.executeQuery(sqll);
vector.removeAllElements();
tm.fireTableStructureChanged();
while (rs.next()) {
Vector rec_vector = new Vector();
rec_vector.addElement(String.valueOf(rs.getInt(1)));
rec_vector.addElement(String.valueOf(rs.getInt(2)));
rec_vector.addElement(String.valueOf(rs.getInt(3)));
rec_vector.addElement(String.valueOf(rs.getInt(4)));
rec_vector.addElement(rs.getString(5));
rec_vector.addElement(rs.getString(6));
rec_vector.addElement(rs.getString(7));
rec_vector.addElement(rs.getString(8));
rec_vector.addElement(rs.getString(9));
rec_vector.addElement(rs.getString(10));
rec_vector.addElement(String.valueOf(rs.getInt(11)));
vector.addElement(rec_vector);
}
tm.fireTableStructureChanged();
}
}
catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
}
void updated() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "admin");
statement = connection.createStatement();
String sql3 = "select * from room_info";
rSet = statement.executeQuery(sql3);
if (rSet.next() == true) {
String sql = "select * from room_info";
ResultSet rs = statement.executeQuery(sql);
vector.removeAllElements();
tm.fireTableStructureChanged();
while (rs.next()) {
Vector rec_vector = new Vector();
rec_vector.addElement(String.valueOf(rs.getInt(1)));
rec_vector.addElement(String.valueOf(rs.getInt(2)));
rec_vector.addElement(String.valueOf(rs.getInt(3)));
rec_vector.addElement(String.valueOf(rs.getInt(4)));
rec_vector.addElement(rs.getString(5));
rec_vector.addElement(rs.getString(6));
rec_vector.addElement(rs.getString(7));
rec_vector.addElement(rs.getString(8));
rec_vector.addElement(rs.getString(9));
rec_vector.addElement(rs.getString(10));
rec_vector.addElement(String.valueOf(rs.getInt(11)));
vector.addElement(rec_vector);
}
tm.fireTableStructureChanged();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
}
void renewButton_actionPerformed(ActionEvent e) {
districtid.setText("");
buildingid.setText("");
roomid.setText("");
area.setText("");
ownername.setText("");
sex.setText("");
idnum.setText("");
addr.setText("");
tetel.setText("");
}
}
5.修改收费单价
package com.sjsq;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
/**
* 收费单价修改
* @author 水坚石青
*
*/
public class PriceChangeFrame extends JFrame {
private Connection c1;
private String Mouaction;
private JTable display;
private JButton comm_1, comm_2, comm_3;
private Statement stmt1;
private ResultSet rsl1;
private ResultSetMetaData rsmd1;
private TextField text_1, text_2, text_3;
public PriceChangeFrame() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
c1 = DriverManager.getConnection("jdbc:mysql://localhost:3306/swing_property?serverTimezone=UTC", "root", "admin");
String sql = "SELECT * FROM unit_price_info";
stmt1 = c1.createStatement();
rsl1 = stmt1.executeQuery(sql);
rsmd1 = rsl1.getMetaData();// 获取表的字段名称
} catch (Exception err) {
err.printStackTrace();
} // 建立数据库连接;
JPanel button_con = new JPanel();
button_con.setLayout(new FlowLayout());
comm_1 = new JButton("增加");
comm_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addPrice();
}
});
comm_2 = new JButton("修改");
comm_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changePrice();
}
});
comm_3 = new JButton("删除");
comm_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deletePrice();
}
});
button_con.add(comm_1);
button_con.add(comm_2);
button_con.add(comm_3);
JPanel label_con = new JPanel();
label_con.setLayout(new GridLayout(1, 3));
JLabel lab_1 = new JLabel("收费项目编号");
JLabel lab_2 = new JLabel("收费项目名称");
JLabel lab_3 = new JLabel("单价");
label_con.add(lab_1);
label_con.add(lab_2);
label_con.add(lab_3);
JPanel inputText_con = new JPanel();
inputText_con.setLayout(new GridLayout(1, 3));
text_1 = new TextField();
text_2 = new TextField();
text_3 = new TextField();
inputText_con.add(text_1);
inputText_con.add(text_2);
inputText_con.add(text_3);
JPanel update_con = new JPanel();
update_con.setLayout(new BorderLayout());
update_con.add(label_con, BorderLayout.NORTH);
update_con.add(inputText_con, BorderLayout.CENTER);
update_con.add(button_con, BorderLayout.SOUTH);
display = new JTable();
Container temp = getContentPane();
temp.setLayout(new BorderLayout());
temp.add(update_con, BorderLayout.SOUTH);
temp.add(display, BorderLayout.CENTER);
getpriceTable();
setSize(500, 300);
setLocationRelativeTo(null);
show();
}
public void getpriceTable() {
try {
Vector columnName = new Vector();
Vector rows = new Vector();// 定义向量,进行数据库数据操作
columnName.addElement("收费项目编号");
columnName.addElement("收费项目名称");
columnName.addElement("单价(单位:元)");
while (rsl1.next()) { // 获取记录集
Vector currentRow = new Vector();
for (int i = 1; i <= rsmd1.getColumnCount(); ++i) {
currentRow.addElement(rsl1.getString(i));
}
rows.addElement(currentRow);
}
display = new JTable(rows, columnName);
JScrollPane scroller = new JScrollPane(display);
Container temp = getContentPane();
temp.add(scroller, BorderLayout.CENTER);
temp.validate();
} catch (Exception sqlex) {
sqlex.printStackTrace();
}
}
private void addPrice() {
try {
String add_sql = "insert into unit_price_info values (" + Integer.parseInt(text_1.getText()) + ",'"
+ text_2.getText() + "'," + Float.parseFloat(text_3.getText()) + ")";
stmt1.executeUpdate(add_sql);
text_1.setText("");
text_2.setText("");
text_3.setText("");
} catch (Exception ex) {
JOptionPane.showMessageDialog(PriceChangeFrame.this, "增加数据出错,注意所填数据是否正确!", "错误", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
}
}
private void changePrice() {
try {
String change_sql = "update unit_price_info set charge_id=" + Integer.parseInt(text_1.getText())
+ ",charge_name='" + text_2.getText() + "',unit_price=" + Float.parseFloat(text_3.getText())
+ " where charge_id=" + Integer.parseInt(text_1.getText());
stmt1.executeUpdate(change_sql);
text_1.setText("");
text_2.setText("");
text_3.setText("");
} catch (Exception ex_1) {
JOptionPane.showMessageDialog(PriceChangeFrame.this, "修改数据出错,注意所填数据是否正确!", "错误", JOptionPane.ERROR_MESSAGE);
ex_1.printStackTrace();
}
}
private void deletePrice() {
try {
String delete_sql = "delete from unit_price_info where charge_id=" + Integer.parseInt(text_1.getText());
;
stmt1.executeUpdate(delete_sql);
text_1.setText("");
text_2.setText("");
text_3.setText("");
} catch (Exception ex_2) {
JOptionPane.showMessageDialog(PriceChangeFrame.this, "增加数据出错,注意所填收费项目ID是否正确!", "错误", JOptionPane.ERROR_MESSAGE);
ex_2.printStackTrace();
}
}
public static void main(String args[]) {
PriceChangeFrame s1 = new PriceChangeFrame();
s1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
四、其他事宜
1.更多系统
Java+JavaFx系统系列实现
Java+Swing系统系列实现
Java+JSP系统系列实现
Java+Servlet系统系列实现
Java+SSM系统系列实现
Java+SSH系统系列实现
Java+Springboot系统系列实现
Java+Springboot+H-ui+Maven实现营销管理系统
Java+Springboot+Bootstrap+Maven实现网上商城系统
Java+Springboot+Bootstrap+Maven实现景区旅游管理系统
1.更多JavaWeb系统请关注专栏。
https://blog.youkuaiyun.com/helongqiang/category_10020130.html
2.更多JavaSwing系统请关注专栏。
https://blog.youkuaiyun.com/helongqiang/category_6229101.html
2.运行项目
3.权益备注
如有侵权请联系我删除。
4.支持博主
如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!
469

被折叠的 条评论
为什么被折叠?



