「旅游信息管理系统」 · Java Swing + MySQL 开发

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 「旅游信息管理系统」 · Java Swing + MySQL 开发

一、需求简介:


该旅游管理信息系统可以为游客和公司业务管理员提供服务。游客可以对旅游路线,旅游班次,旅游团,保险,导游,交通工具以及宾馆的信息查询,并且游客可以在线报名旅游。同时公司业务管理员可以对所有报名信息进行处理,确认之后导出报名信息交由旅行社。


业务流程及系统概念模型如下:

游客:


59.png


业务管理员:


60.png


旅游业务模型:


61.png


整体概要设计:


62.png


二、界面示例:

首页:63.png


点击报名:如果没有登录提示游客登录


64.png



登录界面:


65.png



注册界面:


66.png


报名:


67.png


报名信息管理界面:


68.png


报名信息导出生成EXCEL表格:


69.png


三、实现代码:

1、数据库:


/*
Navicat MySQL Data Transfer
Source Server         : test
Source Server Version : 50646
Source Host           : localhost:3306
Source Database       : travel_manage
Target Server Type    : MYSQL
Target Server Version : 50646
File Encoding         : 65001
Date: 2020-09-02 10:15:48
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for tourism_group
-- ----------------------------
DROP TABLE IF EXISTS `tourism_group`;
CREATE TABLE `tourism_group` (
  `group_num` int(10) NOT NULL AUTO_INCREMENT,
  `group_name` varchar(20) NOT NULL,
  `group_contact` varchar(20) NOT NULL,
  `group_address` varchar(20) NOT NULL,
  `group_phone` varchar(20) NOT NULL,
  PRIMARY KEY (`group_num`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tourism_group
-- ----------------------------
INSERT INTO `tourism_group` VALUES ('1', '魔方格旅游团', '杨文', '云南省昆明市五华区龙翔街道茭菱路128号', '18214217246');
-- ----------------------------
-- Table structure for tourism_line
-- ----------------------------
DROP TABLE IF EXISTS `tourism_line`;
CREATE TABLE `tourism_line` (
  `route_num` int(10) NOT NULL AUTO_INCREMENT,
  `origin` varchar(30) NOT NULL,
  `destination` varchar(30) NOT NULL,
  `day_num` int(10) NOT NULL,
  `attractions` varchar(30) NOT NULL,
  PRIMARY KEY (`route_num`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tourism_line
-- ----------------------------
INSERT INTO `tourism_line` VALUES ('1', '昆明', '丽江', '10', '丽江古城');
INSERT INTO `tourism_line` VALUES ('2', '昆明', '大理', '5', '大理古城');
INSERT INTO `tourism_line` VALUES ('10', '昆明', '丽江', '10', '大观楼');
INSERT INTO `tourism_line` VALUES ('11', '昆明', '湖南', '5', '翠湖');
INSERT INTO `tourism_line` VALUES ('12', '昆明', '上海', '3', '世博园');
INSERT INTO `tourism_line` VALUES ('13', '昆明', '南京', '6', '花之城');
INSERT INTO `tourism_line` VALUES ('14', '昆明', '上海', '7', '瀑布公园');
INSERT INTO `tourism_line` VALUES ('15', '昆明', '武汉', '8', '花之城');
INSERT INTO `tourism_line` VALUES ('16', '昆明', '成都', '3', '世博园');
INSERT INTO `tourism_line` VALUES ('17', '昆明', '四川', '11', '翠湖');
INSERT INTO `tourism_line` VALUES ('18', '昆明', '贵州', '4', '湿地公园');
INSERT INTO `tourism_line` VALUES ('19', '昆明', '遵义', '14', '花之城');
INSERT INTO `tourism_line` VALUES ('20', '昆明', '长沙', '8', '陆军讲武堂');
INSERT INTO `tourism_line` VALUES ('21', '昆明', '建水', '9', '大观楼');
INSERT INTO `tourism_line` VALUES ('22', '昆明', '红河', '7', '翠湖');
-- ----------------------------
-- Table structure for tourist
-- ----------------------------
DROP TABLE IF EXISTS `tourist`;
CREATE TABLE `tourist` (
  `tourist_num` int(20) NOT NULL AUTO_INCREMENT,
  `user_id` int(20) NOT NULL,
  `tourist_name` varchar(20) NOT NULL,
  `tourist_sex` char(10) NOT NULL,
  `tourist_age` int(20) NOT NULL,
  `tourist_idcard` varchar(20) NOT NULL,
  `tourist_address` varchar(50) NOT NULL,
  `tourist_phone` varchar(20) NOT NULL,
  `group_num` int(11) NOT NULL,
  `accompanied` varchar(20) NOT NULL,
  `accommodation` varchar(20) NOT NULL,
  PRIMARY KEY (`tourist_num`)
) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_account` varchar(20) NOT NULL,
  `user_password` varchar(20) NOT NULL,
  `user_type` varchar(20) NOT NULL,
  `user_state` varchar(20) NOT NULL,
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('1', '杨明金', '123456', '管理员', '已登录');
INSERT INTO `user` VALUES ('2', '颜权昌', '111111', '游客', '未登录');
INSERT INTO `user` VALUES ('4', '郭超', '111111', '游客', '未登录');
INSERT INTO `user` VALUES ('5', '冯润泽', '111111', '游客', '未登录');


2、Java

com.ynavc.Bean

Tourism_Group.Java


package com.ynavc.Bean;
//旅游团表
public class Tourism_Group {
  String group_num;//团号
  String group_name;//团名
  String group_contact;//联系人
  String group_address;//地址
  String group_phone;//电话
  @Override
  public String toString() {
    return "Tourism_Group [group_num=" + group_num + ", group_name=" + group_name + ", group_contact="
        + group_contact + ", group_address=" + group_address + ", group_phone=" + group_phone + "]";
  }
  public Tourism_Group(String group_num, String group_name, String group_contact, String group_address,
      String group_phone) {
    super();
    this.group_num = group_num;
    this.group_name = group_name;
    this.group_contact = group_contact;
    this.group_address = group_address;
    this.group_phone = group_phone;
  }
  public Tourism_Group() {
    super();
  }
  public String getGroup_num() {
    return group_num;
  }
  public void setGroup_num(String group_num) {
    this.group_num = group_num;
  }
  public String getGroup_name() {
    return group_name;
  }
  public void setGroup_name(String group_name) {
    this.group_name = group_name;
  }
  public String getGroup_contact() {
    return group_contact;
  }
  public void setGroup_contact(String group_contact) {
    this.group_contact = group_contact;
  }
  public String getGroup_address() {
    return group_address;
  }
  public void setGroup_address(String group_address) {
    this.group_address = group_address;
  }
  public String getGroup_phone() {
    return group_phone;
  }
  public void setGroup_phone(String group_phone) {
    this.group_phone = group_phone;
  }
}


Tourism_Line.Java


package com.ynavc.Bean;
//旅游线路表
public class Tourism_Line {
  String route_num;//路线号
  String origin;//起点
  String destination;//终点
  String day_num;//天数
  String attractions;//主要景点
  @Override
  public String toString() {
    return "Tourism_Line [route_num=" + route_num + ", origin=" + origin + ", destination=" + destination
        + ", day_num=" + day_num + ", attractions=" + attractions + "]";
  }
  public Tourism_Line(String route_num, String origin, String destination, String day_num, String attractions) {
    super();
    this.route_num = route_num;
    this.origin = origin;
    this.destination = destination;
    this.day_num = day_num;
    this.attractions = attractions;
  }
  public Tourism_Line() {
    super();
  }
  public String getRoute_num() {
    return route_num;
  }
  public void setRoute_num(String route_num) {
    this.route_num = route_num;
  }
  public String getOrigin() {
    return origin;
  }
  public void setOrigin(String origin) {
    this.origin = origin;
  }
  public String getDestination() {
    return destination;
  }
  public void setDestination(String destination) {
    this.destination = destination;
  }
  public String getDay_num() {
    return day_num;
  }
  public void setDay_num(String day_num) {
    this.day_num = day_num;
  }
  public String getAttractions() {
    return attractions;
  }
  public void setAttractions(String attractions) {
    this.attractions = attractions;
  }
}


Tourist.Java

package com.ynavc.Bean;
//游客信息表
public class Tourist {
  String tourist_num;//游客编号
  String user_id;//用户ID
  String tourist_name;//姓名
  String tourist_sex;//性别
  String tourist_age;//年龄
  String tourist_idCard;//身份证号码
  String tourist_address;//地址
  String tourist_phone;//电话
  String group_num;//旅游团号
  String accompanied;//陪同
  String accommodation;//食宿
  @Override
  public String toString() {
    return "Tourist [tourist_num=" + tourist_num + ", user_id=" + user_id + ", tourist_name=" + tourist_name
        + ", tourist_sex=" + tourist_sex + ", tourist_age=" + tourist_age + ", tourist_idCard=" + tourist_idCard
        + ", tourist_address=" + tourist_address + ", tourist_phone=" + tourist_phone + ", group_num="
        + group_num + ", acompanied=" + accompanied + ", accommdation=" + accommodation + "]";
  }
  public Tourist(String tourist_num, String user_id, String tourist_name, String tourist_sex, String tourist_age,
      String tourist_idCard, String tourist_address, String tourist_phone, String group_num, String acompanied,
      String accommdation) {
    super();
    this.tourist_num = tourist_num;
    this.user_id = user_id;
    this.tourist_name = tourist_name;
    this.tourist_sex = tourist_sex;
    this.tourist_age = tourist_age;
    this.tourist_idCard = tourist_idCard;
    this.tourist_address = tourist_address;
    this.tourist_phone = tourist_phone;
    this.group_num = group_num;
    this.accompanied = acompanied;
    this.accommodation = accommdation;
  }
  public Tourist() {
    super();
  }
  public String getTourist_num() {
    return tourist_num;
  }
  public void setTourist_num(String tourist_num) {
    this.tourist_num = tourist_num;
  }
  public String getUser_id() {
    return user_id;
  }
  public void setUser_id(String user_id) {
    this.user_id = user_id;
  }
  public String getTourist_name() {
    return tourist_name;
  }
  public void setTourist_name(String tourist_name) {
    this.tourist_name = tourist_name;
  }
  public String getTourist_sex() {
    return tourist_sex;
  }
  public void setTourist_sex(String tourist_sex) {
    this.tourist_sex = tourist_sex;
  }
  public String getTourist_age() {
    return tourist_age;
  }
  public void setTourist_age(String tourist_age) {
    this.tourist_age = tourist_age;
  }
  public String getTourist_idCard() {
    return tourist_idCard;
  }
  public void setTourist_idCard(String tourist_idCard) {
    this.tourist_idCard = tourist_idCard;
  }
  public String getTourist_address() {
    return tourist_address;
  }
  public void setTourist_address(String tourist_address) {
    this.tourist_address = tourist_address;
  }
  public String getTourist_phone() {
    return tourist_phone;
  }
  public void setTourist_phone(String tourist_phone) {
    this.tourist_phone = tourist_phone;
  }
  public String getGroup_num() {
    return group_num;
  }
  public void setGroup_num(String group_num) {
    this.group_num = group_num;
  }
  public String getAccompanied() {
    return accompanied;
  }
  public void setAccompanied(String accompanied) {
    this.accompanied = accompanied;
  }
  public String getAccommodation() {
    return accommodation;
  }
  public void setAccommodation(String accommdation) {
    this.accommodation = accommdation;
  }
}


User.Java

package com.ynavc.Bean;
//用户登录信息表
public class User {
  String user_id;//用户ID
  String user_account;//用户账户
  String user_password;//用户密码
  String user_type;//用户类型
  @Override
  public String toString() {
    return "User [user_id=" + user_id + ", user_account=" + user_account + ", user_password=" + user_password
        + ", user_type=" + user_type + "]";
  }
  public User() {
    super();
  }
  public User(String user_id, String user_account, String user_password, String user_type) {
    super();
    this.user_id = user_id;
    this.user_account = user_account;
    this.user_password = user_password;
    this.user_type = user_type;
  }
  public String getUser_id() {
    return user_id;
  }
  public void setUser_id(String user_id) {
    this.user_id = user_id;
  }
  public String getUser_account() {
    return user_account;
  }
  public void setUser_account(String user_account) {
    this.user_account = user_account;
  }
  public String getUser_password() {
    return user_password;
  }
  public void setUser_password(String user_password) {
    this.user_password = user_password;
  }
  public String getUser_type() {
    return user_type;
  }
  public void setUser_type(String user_type) {
    this.user_type = user_type;
  }
}


com.ynavc.Controller

Select.Java


package com.ynavc.Controller;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.ynavc.Bean.Tourism_Line;
import com.ynavc.Bean.Tourist;
import com.ynavc.Dao.DbConnection;
public class Select{
  //查询数据条数
  public int getCount(String sql) {
    ResultSet resultSet=DbConnection.query(sql);
    try {
      if (resultSet.next()) {
        return resultSet.getInt(1);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return 0;
  }
  //得到一条数据
  public String getString(String sql) {
    ResultSet resultSet=DbConnection.query(sql);
    try {
      if (resultSet.next()) {
        return resultSet.getString(1);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return null;
  }
  //用户登录
  public int Select(String account ,String password) {
    String sql="select * from UserInfo where password='"+password+"'  and account='"+account+"'";
    ResultSet resultSet=DbConnection.query(sql);
    int a=0;
    try {
      while (resultSet.next()) {
        a=1;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return a;
  }
  //旅游信息表
  public Object[][] getLineInfo() {
    String sql="SELECT * FROM tourism_line";
    ResultSet resultSet = DbConnection.query(sql);
    ArrayList<Tourism_Line> list=new ArrayList<Tourism_Line>();
    try {
      while (resultSet.next()) {
        Tourism_Line t=new Tourism_Line();
        t.setRoute_num(resultSet.getString(1));
        t.setOrigin(resultSet.getString(2));
        t.setDestination(resultSet.getString(3));
        t.setDay_num(resultSet.getString(4));
        t.setAttractions(resultSet.getString(5));
        list.add(t);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    Object[][] objects=new Object[list.size()][5];
    for(int i=0;i<list.size();i++) {
      objects[i][0]=list.get(i).getRoute_num();
      objects[i][1]=list.get(i).getOrigin();
      objects[i][2]=list.get(i).getDestination();
      objects[i][3]=list.get(i).getDay_num();
      objects[i][4]=list.get(i).getAttractions();
    }
    return objects;
  }
  //旅游信息表
  public Object[][] getTourist(String sql) {
//    String sql="SELECT * FROM tourist";
    ResultSet resultSet = DbConnection.query(sql);
    ArrayList<Tourist> list=new ArrayList<Tourist>();
    try {
      while (resultSet.next()) {
        Tourist t=new Tourist();
        t.setTourist_num(resultSet.getString(1));
        t.setUser_id(resultSet.getString(2));
        t.setTourist_name(resultSet.getString(3));
        t.setTourist_sex(resultSet.getString(4));
        t.setTourist_age(resultSet.getString(5));
        t.setTourist_idCard(resultSet.getString(6));
        t.setTourist_address(resultSet.getString(7));
        t.setTourist_phone(resultSet.getString(8));
        t.setGroup_num(resultSet.getString(9));
        t.setAccompanied(resultSet.getString(10));
        t.setAccommodation(resultSet.getString(11));
        list.add(t);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    Object[][] objects=new Object[list.size()][10];
    for(int i=0;i<list.size();i++) {
      objects[i][0]=list.get(i).getTourist_num();
//      objects[i][1]=list.get(i).getUser_id();
      objects[i][1]=list.get(i).getTourist_name();
      objects[i][2]=list.get(i).getTourist_sex();
      objects[i][3]=list.get(i).getTourist_age();
      objects[i][4]=list.get(i).getTourist_idCard();
      objects[i][5]=list.get(i).getTourist_address();
      objects[i][6]=list.get(i).getTourist_phone();
      objects[i][7]=list.get(i).getGroup_num();
      objects[i][8]=list.get(i).getAccompanied();
      objects[i][9]=list.get(i).getAccommodation();
    }
    return objects;
  }
}


Updata.Java

package com.ynavc.Controller;
import com.ynavc.Dao.DbConnection;
public class Updata {
  //添加数据
  public int addData(String sql) {
    return DbConnection.updataInfo(sql);
  }
}



com.ynavc.Dao

DbConnection.Java


package com.ynavc.Dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
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://118.31.124.77:3306/mydb23660";
  private static final String URL="jdbc:mysql://127.0.0.1:3306/travel_manage";
  //数据库登录账号
//  private static final String USER="mydb23660";
  private static final String USER="root";
  //数据库登录密码
//  private static final String PASSWORD="Hmsyfjdglxt66";
  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) {
      JOptionPane.showMessageDialog(null,"执行语句出错\n"+e.toString());
      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) {
        JOptionPane.showMessageDialog(null,"执行语句出错\n"+e.toString());
        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.ynavc.View

MainJframe.Java


package com.ynavc.View;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.Timer;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
public class MainJframe extends JFrame {
  Select select = new Select();
  Updata updata = new Updata();
  Object[] header= {"线路号","起点","终点","天数","主要景点"};
  Object[][] data=select.getLineInfo();
  public MainJframe() {
    super("旅游管理信息系统");
    this.setBounds(0, 0, 1200, 700);
    this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
    this.setResizable(false);//让窗口大小不可改变
    getContentPane().setLayout(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//用户单击窗口的关闭按钮时程序执行的操作
    //按钮
    ImageIcon i1 = new ImageIcon("img/Icon1.png");
    JButton xxcx = new JButton("旅游信息查询",i1);
    xxcx.setBounds(14, 11, 145, 35);
    xxcx.setFocusPainted(false);//去掉按钮周围的焦点框
    xxcx.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(xxcx);
    xxcx.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        JOptionPane.showMessageDialog(null, "此功能暂未开放!");
      }
    });
    ImageIcon i2 = new ImageIcon("img/Icon2.png");
    JButton bmly = new JButton("报名旅游",i2);
    bmly.setBounds(164, 11, 110, 35);
    bmly.setFocusPainted(false);//去掉按钮周围的焦点框
    bmly.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(bmly);
    bmly.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        //判断当前是否有用户登录
        String sql = "SELECT COUNT(*) FROM `user` WHERE user_state='已登录'";
        int reselt = select.getCount(sql);
        if (reselt>0) {
          Registration_Info r = new Registration_Info();
          r.setVisible(true);
        } else {
          JOptionPane.showMessageDialog(null, "请先登录!");
          Login l = new Login();
          l.setVisible(true);
          dispose();
        }
      }
    });
    ImageIcon i3 = new ImageIcon("img/Icon3.png");
    JButton ywgl = new JButton("业务管理员",i3);
    ywgl.setBounds(279, 11, 130, 35);
    ywgl.setFocusPainted(false);//去掉按钮周围的焦点框
    ywgl.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(ywgl);
    ywgl.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        //判断当前是否有用户登录
        String sql = "SELECT COUNT(*) FROM `user` WHERE user_state='已登录'";
        int reselt = select.getCount(sql);
        if (reselt>0) {
          //判断当前登录的用户身份
          String user_type = select.getString("SELECT user_type FROM `user` WHERE user_state='已登录'");
          if (user_type.equals("管理员")) {
            Registration_Management r = new Registration_Management();
            r.setVisible(true);
            dispose();
          }else{
            JOptionPane.showMessageDialog(null, "当前无权限!请登录管理员账号!");
          }
        } else {
          JOptionPane.showMessageDialog(null, "请先登录!");
          Login l = new Login();
          l.setVisible(true);
          dispose();
        }
      }
    });
    ImageIcon i4 = new ImageIcon("img/Icon4.png");
    JButton yhdl = new JButton("登录",i4);
    yhdl.setBounds(414, 11, 85, 35);
    yhdl.setFocusPainted(false);//去掉按钮周围的焦点框
    yhdl.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(yhdl);
    yhdl.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        //判断当前是否有用户登录
        String sql = "SELECT COUNT(*) FROM `user` WHERE user_state='已登录'";
        int reselt = select.getCount(sql);
        if (reselt>0) {
          String i = select.getString("SELECT user_account FROM `user` WHERE user_state='已登录'");
          JOptionPane.showMessageDialog(null, "当前已有用户"+"   ”"+i+"”   "+"登录");
        }else {
          Login l = new Login();
          l.setVisible(true);
          dispose();
        }
      }
    });
    ImageIcon i5 = new ImageIcon("img/Icon5.png");
    JButton yhzc = new JButton("注册",i5);
    yhzc.setBounds(504, 11, 85, 35);
    yhzc.setFocusPainted(false);//去掉按钮周围的焦点框
    yhzc.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(yhzc);
    yhzc.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        //判断当前是否有用户登录
        String sql = "SELECT COUNT(*) FROM `user` WHERE user_state='已登录'";
        int reselt = select.getCount(sql);
        if (reselt>0) {
          String i = select.getString("SELECT user_account FROM `user` WHERE user_state='已登录'");
//          JOptionPane.showMessageDialog(null, "当前已有用户"+"   ”"+i+"”   "+"登录!是否注销?");
          int a = JOptionPane.showConfirmDialog(null,"当前已有用户"+"   ”"+i+"”   "+"登录!是否注销?","注销提示",0,1);
          if(a == JOptionPane.OK_OPTION){
            JOptionPane.showMessageDialog(null, "已注销前账户!");
            updata.addData("UPDATE user SET user_state='未登录' WHERE user_account='"+i+"';");
            Registered r = new Registered();
            r.setVisible(true);
            dispose();
                  }
        }else {
          Registered r = new Registered();
          r.setVisible(true);
          dispose();
        }
      }
    });
    ImageIcon i6 = new ImageIcon("img/Icon6.png");
    JButton tcxt = new JButton("退出系统",i6);
    tcxt.setBounds(594, 11, 110, 35);
    tcxt.setFocusPainted(false);//去掉按钮周围的焦点框
    tcxt.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(tcxt);
    tcxt.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        int result = JOptionPane.showConfirmDialog(null,"您现在要关闭系统吗?关闭后同时注销账号!","退出提示",0,1);
        if(result == JOptionPane.OK_OPTION){
          JOptionPane.showMessageDialog(null, "已退出系统,欢迎下次使用!");
          updata.addData("UPDATE user SET user_state='未登录';");
                    System.exit(0);
                }
      }
    });
    ImageIcon i7 = new ImageIcon("img/Icon7.png");
    JButton help = new JButton("帮助",i2);
    help.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(null, "系统管理员电话:18214217246");
      }
    });
    help.setBounds(709, 11, 85, 35);
    help.setFocusPainted(false);//去掉按钮周围的焦点框
    help.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(help);
    JLabel dqsj = new JLabel("当前时间 :");
//    dqsj.setForeground(Color.decode("#7784BD"));
    dqsj.setBounds(857, 13, 85, 35);
    dqsj.setFont(new Font("微软雅黑", Font.BOLD, 15));
    getContentPane().add(dqsj);
    JLabel time1 = new JLabel();
//    time1.setForeground(Color.decode("#7784BD"));
    time1.setBounds(944, 14, 236, 35);
    time1.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
    getContentPane().add(time1);
    this.setTimer(time1);
    //创建表模型
    DefaultTableModel dt=new DefaultTableModel(data,header){
      //设置表格内容不可被编辑
         public boolean isCellEditable(int row, int column) {
            return false;//返回true表示能编辑,false表示不能编辑
           }
    };
    JTable jTable=new JTable(dt);//创建表格
    jTable.getTableHeader().setFont(new Font(null, Font.BOLD, 14));  // 设置表头名称字体样式
    jTable.getTableHeader().setForeground(Color.black);                // 设置表头名称字体颜色
    jTable.getTableHeader().setResizingAllowed(false);               // 设置不允许手动改变列宽
    jTable.getTableHeader().setReorderingAllowed(false);//设置表头不允许拖动
    int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;//水平滚动条
    int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;//垂直滚动条
    JScrollPane jsp=new JScrollPane(jTable,v,h);//创建滚动容器
    jsp.setBounds(14, 68, 1166, 584);
    getContentPane().add(jsp);
    //设置单元格内容居中显示
    DefaultTableCellRenderer r = new DefaultTableCellRenderer();   
    r.setHorizontalAlignment(JLabel.CENTER); 
    jTable.setDefaultRenderer(Object.class, r);
  }
  // 设置Timer 1000ms实现一次动作 实际是一个线程
  private void setTimer(JLabel time) {
    final JLabel varTime = time;
    Timer timeAction = new Timer(100, new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        long timemillis = System.currentTimeMillis();
        // 转换日期显示格式
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        varTime.setText(df.format(new Date(timemillis)));
      }
    });
    timeAction.start();
  }
  public static void main(String[] args) {
    MainJframe m = new MainJframe();
    m.setVisible(true);
  }
}


Login.Java


package com.ynavc.View;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import javax.swing.JButton;
public class Login extends JFrame {
  Select select = new Select();
  Updata updata = new Updata();
  private JTextField textField_zh;
  private JPasswordField textField_mm;
  public Login() { 
    super.setTitle("系统登录");
    this.setBounds(0, 0, 700, 550);//设置大小
    this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
        this.setResizable(false);//让窗口大小不可改变
    getContentPane().setLayout(null);
    JLabel label_zh = new JLabel("账号:");
    label_zh.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
    label_zh.setBounds(183, 135, 72, 18);
    getContentPane().add(label_zh);
    textField_zh = new JTextField();
    textField_zh.setBounds(233, 130, 270, 34);
    getContentPane().add(textField_zh);
    textField_zh.setColumns(10);
    JLabel label_mm = new JLabel("密码:");
    label_mm.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
    label_mm.setBounds(183, 205, 72, 18);
    getContentPane().add(label_mm);
    textField_mm = new JPasswordField();
    textField_mm.setBounds(233, 200, 270, 34);
    getContentPane().add(textField_mm);
    textField_mm.setColumns(10);
    JButton button = new JButton("登录");
    button.setFont(new Font("宋体", Font.BOLD, 20));
    button.setBounds(282, 299, 113, 34);
    button.setFocusPainted(false);//去掉按钮周围的焦点框
    button.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button);
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        String account=textField_zh.getText();
        String password=textField_mm.getText();
        if (account.equals("")&&password.equals("")) {
          JOptionPane.showMessageDialog(null, "账户名或密码未填写!");
        } else {
          String sql = "select COUNT(*) from user where user_password='"+password+"' and user_account='"+account+"'";
          int reselt = select.getCount(sql);
          int i = updata.addData("UPDATE user SET user_state='已登录' WHERE user_account='"+account+"';");
          if (reselt>0&&i>0) {
            JOptionPane.showMessageDialog(null, "登录成功!欢迎使用!");
            MainJframe m = new MainJframe();
            m.setVisible(true);
            dispose();
          } else {
            JOptionPane.showMessageDialog(null, "登录失败!账户名或密码不正确!请重新输入!");
          }
        }
      }
    });
    JLabel ljzc = new JLabel("没有账号?立即注册!");
    ljzc.setFont(new Font("宋体", Font.ITALIC, 16));
    ljzc.setForeground(Color.blue);
    ljzc.setBounds(271, 380, 168, 27);
    getContentPane().add(ljzc);
    ljzc.addMouseListener(new MouseListener(){
      public void mouseClicked(MouseEvent e) {
        // 处理鼠标点击
        Registered m = new Registered();
        m.setVisible(true);
        dispose();
      }
      public void mouseEntered(MouseEvent e) {
        // 处理鼠标移入
        ljzc.setForeground(Color.red);
      }
      public void mouseExited(MouseEvent e) {
        // 处理鼠标离开
        ljzc.setForeground(Color.blue);
      }
      public void mousePressed(MouseEvent e) {
        // 处理鼠标按下
      }
      public void mouseReleased(MouseEvent e) {
        // 处理鼠标释放
      }
    });
    this.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        super.windowClosing(e);
        //加入动作
        MainJframe m = new MainJframe();
        m.setVisible(true);
       }
    });
  }
}


Registered.Java


package com.ynavc.View;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.ynavc.Controller.Updata;
public class Registered extends JFrame {
  Updata updata = new Updata();
  private JTextField textField_zh;
  private JPasswordField textField_srmm;
  private JPasswordField textField_qrmm;
  public Registered() {
    super.setTitle("账号注册");
    this.setBounds(0, 0, 700, 550);//设置大小
    this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
        this.setResizable(false);//让窗口大小不可改变
    getContentPane().setLayout(null);
    this.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        super.windowClosing(e);
        //加入动作
        MainJframe m = new MainJframe();
        m.setVisible(true);
       }
    });
    JLabel label_zh = new JLabel("账号名:");
    label_zh.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
    label_zh.setBounds(165, 138, 72, 18);
    getContentPane().add(label_zh);
    textField_zh = new JTextField();
    textField_zh.setBounds(248, 130, 255, 34);
    getContentPane().add(textField_zh);
    textField_zh.setColumns(10);
    JLabel label_srmm = new JLabel("输入密码:");
    label_srmm.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
    label_srmm.setBounds(165, 208, 83, 18);
    getContentPane().add(label_srmm);
    textField_srmm = new JPasswordField();
    textField_srmm.setBounds(248, 267, 255, 34);
    getContentPane().add(textField_srmm);
    textField_srmm.setColumns(10);
    JLabel label_qrmm = new JLabel("确认密码:");
    label_qrmm.setFont(new Font("宋体", Font.CENTER_BASELINE, 15));
    label_qrmm.setBounds(165, 275, 92, 18);
    getContentPane().add(label_qrmm);
    textField_qrmm = new JPasswordField();
    textField_qrmm.setBounds(248, 200, 255, 34);
    getContentPane().add(textField_qrmm);
    textField_qrmm.setColumns(10);
    JButton button = new JButton("注册");
    button.setFont(new Font("宋体", Font.BOLD, 20));
    button.setBounds(282, 362, 113, 34);
    button.setFocusPainted(false);//去掉按钮周围的焦点框
    button.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button);
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        String yhm = textField_zh.getText();
        String srmm = textField_srmm.getText();
        String qrmm = textField_qrmm.getText();
        //确认输入的信息是否为空
        if (yhm.equals("")&&srmm.equals("")&&qrmm.equals("")) {
          JOptionPane.showMessageDialog(null, "请完整输入信息!");
        }else {
          //判断两次密码是否一致
          if (srmm.equals(qrmm)) {
            String sql = "INSERT INTO `user` VALUES (null, '"+yhm+"', '"+srmm+"', '游客', '未登录');";
            int reselt = updata.addData(sql);
            if (reselt>0) {
              JOptionPane.showMessageDialog(null, "注册成功!将跳转到登录页面!");
              Login l = new Login();
              l.setVisible(true);
              dispose();
            }else {
              JOptionPane.showMessageDialog(null, "注册失败!");
            }
          }else {
            JOptionPane.showMessageDialog(null, "两次输入的密码不一致!请检查!");
          }
        }
      }
    });
  }
}


Registration_Info.Java


package com.ynavc.View;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import com.ynavc.Utils.ValidateUtils;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
public class Registration_Info extends JFrame {
  private JTextField textField_name;//姓名
  private JTextField textField_age;//年龄
  private JTextField textField_IDcard;//身份证号码
  private JTextField textField_address;//地址
  private JTextField textField_phone;//电话
  private JTextField textField_th;//团号
  private JTextField textField_pt;//陪同
  private JTextField textField_ss;//食宿
  Select select = new Select();
  Updata updata = new Updata();
  String name,sex,age,Idcard,address,phone,th,pt,ss;
  public Registration_Info() {
    super("填写报名信息");
    this.setBounds(0, 0, 930, 700);
    this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
    this.setResizable(false);//让窗口大小不可改变
    getContentPane().setLayout(null);
    JLabel lblNewLabel_name= new JLabel("姓名:");
    lblNewLabel_name.setBounds(138, 79, 72, 18);
    getContentPane().add(lblNewLabel_name);
    textField_name = new JTextField();
    textField_name.setBounds(191, 76, 240, 24);
    getContentPane().add(textField_name);
    textField_name.setColumns(10);
    JLabel lblNewLabel_sex= new JLabel("性别:");
    lblNewLabel_sex.setBounds(138, 125, 72, 18);
    getContentPane().add(lblNewLabel_sex);
    JComboBox comboBox_sez = new JComboBox();
    comboBox_sez.setModel(new DefaultComboBoxModel(new String[] {"男", "女"}));
    comboBox_sez.setBounds(191, 122, 240, 24);
    getContentPane().add(comboBox_sez);
    JLabel lblNewLabel_age= new JLabel("年龄:");
    lblNewLabel_age.setBounds(138, 168, 72, 18);
    getContentPane().add(lblNewLabel_age);
    textField_age = new JTextField();
    textField_age.setBounds(191, 165, 240, 24);
    getContentPane().add(textField_age);
    textField_age.setColumns(10);
    JLabel lblNewLabel_IDcard= new JLabel("身份证号码:");
    lblNewLabel_IDcard.setBounds(93, 213, 117, 18);
    getContentPane().add(lblNewLabel_IDcard);
    textField_IDcard = new JTextField();
    textField_IDcard.setBounds(191, 210, 240, 24);
    getContentPane().add(textField_IDcard);
    textField_IDcard.setColumns(10);
    JLabel lblNewLabel_address= new JLabel("住址:");
    lblNewLabel_address.setBounds(138, 254, 72, 18);
    getContentPane().add(lblNewLabel_address);
    textField_address = new JTextField();
    textField_address.setBounds(191, 251, 240, 24);
    getContentPane().add(textField_address);
    textField_address.setColumns(10);
    JLabel lblNewLabel_phone= new JLabel("电话:");
    lblNewLabel_phone.setBounds(138, 295, 72, 18);
    getContentPane().add(lblNewLabel_phone);
    textField_phone = new JTextField();
    textField_phone.setBounds(191, 292, 240, 24);
    getContentPane().add(textField_phone);
    textField_phone.setColumns(10);
    JLabel lblNewLabel_th= new JLabel("团号:");
    lblNewLabel_th.setBounds(138, 335, 72, 18);
    getContentPane().add(lblNewLabel_th);
    textField_th = new JTextField();
    textField_th.setBounds(191, 332, 240, 24);
    getContentPane().add(textField_th);
    textField_th.setColumns(10);
    JLabel lblNewLabel_pt= new JLabel("陪同:");
    lblNewLabel_pt.setBounds(138, 382, 72, 18);
    getContentPane().add(lblNewLabel_pt);
    textField_pt = new JTextField();
    textField_pt.setText("是否选择导游陪同?");
    textField_pt.setToolTipText("");
    textField_pt.setBounds(191, 379, 240, 24);
    getContentPane().add(textField_pt);
    textField_pt.setColumns(10);
    JLabel lblNewLabel_ss= new JLabel("食宿:");
    lblNewLabel_ss.setBounds(138, 427, 72, 18);
    getContentPane().add(lblNewLabel_ss);
    textField_ss = new JTextField();
    textField_ss.setText("是否选择宾馆住宿?");
    textField_ss.setBounds(191, 424, 240, 24);
    getContentPane().add(textField_ss);
    textField_ss.setColumns(10);
    JButton button_1 = new JButton("查看旅游团信息");
    button_1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      }
    });
    button_1.setBounds(453, 331, 158, 27);
    button_1.setFocusPainted(false);//去掉按钮周围的焦点框
    button_1.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_1);
    JButton button_2 = new JButton("显示选择结果");
    button_2.setBounds(625, 331, 146, 27);
    button_2.setFocusPainted(false);//去掉按钮周围的焦点框
    button_2.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_2);
    JButton button_3 = new JButton("是");
    button_3.setBounds(453, 378, 72, 27);
    button_3.setFocusPainted(false);//去掉按钮周围的焦点框
    button_3.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_3);
    button_3.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        textField_pt.setText("是");
      }
    });
    JButton button_4 = new JButton("否");
    button_4.setBounds(539, 378, 72, 27);
    button_4.setFocusPainted(false);//去掉按钮周围的焦点框
    button_4.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_4);
    button_4.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        textField_pt.setText("无");
      }
    });
    JButton button_5 = new JButton("显示选择结果");
    button_5.setBounds(625, 378, 146, 27);
    button_5.setFocusPainted(false);//去掉按钮周围的焦点框
    button_5.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_5);
    JButton button_6 = new JButton("是");
    button_6.setBounds(453, 421, 72, 27);
    button_6.setFocusPainted(false);//去掉按钮周围的焦点框
    button_6.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_6);
    button_6.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        textField_ss.setText("是");
      }
    });
    JButton button_7 = new JButton("否");
    button_7.setBounds(539, 421, 72, 27);
    button_7.setFocusPainted(false);//去掉按钮周围的焦点框
    button_7.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_7);
    button_7.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        textField_ss.setText("无");
      }
    });
    JButton button_8 = new JButton("显示选择结果");
    button_8.setBounds(625, 423, 146, 27);
    button_8.setFocusPainted(false);//去掉按钮周围的焦点框
    button_8.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_8);
    JButton btnNewButton = new JButton("报名");
    btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 18));
    btnNewButton.setBounds(388, 516, 124, 33);
    btnNewButton.setFocusPainted(false);//去掉按钮周围的焦点框
    btnNewButton.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(btnNewButton);
    btnNewButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        name = textField_name.getText();
        sex = comboBox_sez.getSelectedItem().toString();
        age = textField_age.getText();
        Idcard = textField_IDcard.getText();
        address = textField_address.getText();
        phone = textField_phone.getText();
        th = textField_th.getText();
        pt = textField_pt.getText();
        if (pt.equals("是否选择导游陪同?")) {
          pt="无";
        }
        ss = textField_ss.getText();
        if (ss.equals("是否选择宾馆住宿?")) {
          ss="无";
        }
        //判断输入的信息是否为空,是否完整
        if (name.equals("")||sex.equals("")||age.equals("")||Idcard.equals("")||address.equals("")||phone.equals("")||th.equals("")||pt.equals("")||ss.equals("")) {
          JOptionPane.showMessageDialog(null, "请输入完整信息!");
        } else {
          //判断身份证号码
          if (!ValidateUtils.IDcard(Idcard)) {
            JOptionPane.showMessageDialog(null, "身份证号码错误!请检查!");
          } else {
            String i = select.getString("SELECT user_id FROM `user` WHERE user_state='已登录'");
            String sql = "INSERT INTO `tourist` VALUES (null, '"+i+"', '"+name+"', '"+sex+"', '"+age+"', '"+Idcard+"', '"+address+"', '"+phone+"', '"+th+"', '"+pt+"', '"+ss+"');";
            int result = updata.addData(sql);
            //判断手机号
            String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";
                if(phone.length() != 11){
                  JOptionPane.showMessageDialog(null, "手机号应为11位数!");
                }else{
                    Pattern p = Pattern.compile(regex);
                    Matcher m = p.matcher(phone);
                    boolean isMatch = m.matches();
                    if(!isMatch){
                        JOptionPane.showMessageDialog(null, "您的手机号" + phone + "是错误格式!!!");
                    }else {
                      //判断插入结果
                      if (result>0) {
                        JOptionPane.showMessageDialog(null, "报名成功!");
                        dispose();
                        MainJframe m1 = new MainJframe();
                        m1.setVisible(true);
                      } else {
                        JOptionPane.showMessageDialog(null, "报名失败,请与管理员联系!");
                      }
              }
                }
          }
        }
      }
    });
  }
}



Registration_Management.Java

package com.ynavc.View;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import com.ynavc.Bean.Tourist;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import javax.swing.JTextField;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.awt.event.ActionEvent;
public class Registration_Management extends JFrame {
  Select select = new Select();
  Updata updata = new Updata();
  JButton btnNewButton_Export;
  JTable jTable;
  DefaultTableModel dt;
//  String name,sex,age,Idcard,address,phone,th,pt,ss;
  Object[] header= {"游客编号","姓名","性别","年龄","身份证号","住址","电话","旅游团","陪同","食宿"};
  Object[][] data=select.getTourist("SELECT * FROM tourist");
  private JTextField textField_ykbh;
  private JTextField textField_th;
  private JTextField textField_name;
  public Registration_Management() {
    super("报名信息管理");
    this.setBounds(0, 0, 1200, 700);
    this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
    this.setResizable(false);//让窗口大小不可改变
    getContentPane().setLayout(null);
    this.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        super.windowClosing(e);
        //加入动作
        MainJframe m = new MainJframe();
        m.setVisible(true);
       }
    });
    //创建表模型
    dt=new DefaultTableModel(data,header){
      //设置表格内容不可被编辑
         public boolean isCellEditable(int row, int column) {
            return false;//返回true表示能编辑,false表示不能编辑
           }
    };
    jTable=new JTable(dt);//创建表格
    jTable.getTableHeader().setFont(new Font(null, Font.BOLD, 14));  // 设置表头名称字体样式
    jTable.getTableHeader().setForeground(Color.black);                // 设置表头名称字体颜色
//    jTable.getTableHeader().setResizingAllowed(false);               // 设置不允许手动改变列宽
    jTable.getTableHeader().setReorderingAllowed(false);//设置表头不允许拖动
    int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;//水平滚动条
    int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;//垂直滚动条
    JScrollPane jsp=new JScrollPane(jTable,v,h);//创建滚动容器
    jsp.setBounds(0, 0, 976, 675);
    getContentPane().add(jsp);
    JLabel label_ykbh = new JLabel("游客编号:");
    label_ykbh.setBounds(990, 74, 89, 18);
    getContentPane().add(label_ykbh);
    textField_ykbh = new JTextField();
    textField_ykbh.setBounds(1066, 71, 114, 24);
    getContentPane().add(textField_ykbh);
    textField_ykbh.setColumns(10);
    JLabel label_th = new JLabel("团号:");
    label_th.setBounds(1000, 122, 52, 18);
    getContentPane().add(label_th);
    textField_th = new JTextField();
    textField_th.setColumns(10);
    textField_th.setBounds(1066, 119, 114, 24);
    getContentPane().add(textField_th);
    JLabel label_name = new JLabel("姓名:");
    label_name.setBounds(1000, 168, 52, 18);
    getContentPane().add(label_name);
    textField_name = new JTextField();
    textField_name.setColumns(10);
    textField_name.setBounds(1066, 165, 114, 24);
    getContentPane().add(textField_name);
    JButton btnNewButton_Query = new JButton("查询");
    btnNewButton_Query.setBounds(1031, 224, 113, 27);
    btnNewButton_Query.setFocusPainted(false);//去掉按钮周围的焦点框
    btnNewButton_Query.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(btnNewButton_Query);
    btnNewButton_Query.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        String ykbh,th,name,sql;
        ykbh = textField_ykbh.getText();
        th = textField_th.getText();
        name = textField_name.getText();
        if (ykbh.equals("")&&th.equals("")&&name.equals("")) {
          sql = "SELECT * FROM tourist";
        }else if(ykbh.equals("")&&th.equals("")){
          sql = "SELECT * FROM tourist WHERE tourist_name='"+name+"';";
        }else if(name.equals("")&&th.equals("")){
          sql = "SELECT * FROM tourist WHERE tourist_num='"+ykbh+"';";
        }else if(ykbh.equals("")&&name.equals("")){
          sql = "SELECT * FROM tourist WHERE group_num='"+th+"';";
        }else if(ykbh.equals("")){
          sql = "SELECT * FROM tourist WHERE group_num='"+th+"' and tourist_name='"+name+"';";
        }else if(th.equals("")){
          sql = "SELECT * FROM tourist WHERE tourist_num='"+ykbh+"' and tourist_name='"+name+"';";
        }else if(name.equals("")){
          sql = "SELECT * FROM tourist WHERE tourist_num='"+ykbh+"' and group_num='"+th+"';";
        }else {
          sql = "SELECT * FROM tourist WHERE tourist_num='"+ykbh+"' and group_num='"+th+"' and tourist_name='"+name+"';";
        }
        data = select.getTourist(sql);
        dt.setDataVector(data,header);
      }
    });
    JButton btnNewButton_Alter = new JButton("修改");
    btnNewButton_Alter.setBounds(1031, 278, 113, 27);
    btnNewButton_Alter.setFocusPainted(false);//去掉按钮周围的焦点框
    btnNewButton_Alter.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(btnNewButton_Alter);
    btnNewButton_Alter.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        if (jTable.getSelectedRow()<0) {
          JOptionPane.showMessageDialog(null, "您未选中要修改的数据!");
        } else {
          //获取用户选择的数据
          String name,sex,age,Idcard,address,phone,th,pt,ss;
          String id=jTable.getValueAt(jTable.getSelectedRow(), 0).toString();
          String user_id = select.getString("SELECT user_id FROM `user` WHERE user_state='已登录'");
          name=jTable.getValueAt(jTable.getSelectedRow(), 1).toString();
          sex=jTable.getValueAt(jTable.getSelectedRow(), 2).toString();
          age=jTable.getValueAt(jTable.getSelectedRow(), 3).toString();
          Idcard=jTable.getValueAt(jTable.getSelectedRow(), 4).toString();
          address=jTable.getValueAt(jTable.getSelectedRow(), 5).toString();
          phone=jTable.getValueAt(jTable.getSelectedRow(), 6).toString();
          th=jTable.getValueAt(jTable.getSelectedRow(), 7).toString();
          pt=jTable.getValueAt(jTable.getSelectedRow(), 8).toString();
          ss=jTable.getValueAt(jTable.getSelectedRow(), 9).toString();
          Tourist tourist=new Tourist(id, user_id, name, sex, age, Idcard, address, phone, th, pt, ss);
          RegistrationInfo_Change frame=new RegistrationInfo_Change(tourist);
          frame.setVisible(true);
        }
      }
    });
    JButton btnNewButton_Add = new JButton("添加");
    btnNewButton_Add.setBounds(1031, 330, 113, 27);
    btnNewButton_Add.setFocusPainted(false);//去掉按钮周围的焦点框
    btnNewButton_Add.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(btnNewButton_Add);
    btnNewButton_Add.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        Registration_Info r = new Registration_Info();
        r.setVisible(true);
      }
    });
    JButton btnNewButton_Delete = new JButton("删除");
    btnNewButton_Delete.setBounds(1031, 383, 113, 27);
    btnNewButton_Delete.setFocusPainted(false);//去掉按钮周围的焦点框
    btnNewButton_Delete.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(btnNewButton_Delete);
    btnNewButton_Delete.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        if (jTable.getSelectedRow()<0) {
          JOptionPane.showMessageDialog(null, "您未选中要删除的数据!");
        } else {
          //获取用户选择的数据
          String id=jTable.getValueAt(jTable.getSelectedRow(), 0).toString();
          String name=jTable.getValueAt(jTable.getSelectedRow(), 1).toString();
          int result = JOptionPane.showConfirmDialog(null,"您确定要删除用户  “"+name+"”  的报名信息吗?","删除提示",0,1);
          if(result == JOptionPane.OK_OPTION){
            int i = updata.addData("DELETE FROM tourist WHERE tourist_num='"+id+"';");
            if (i>0){
              JOptionPane.showMessageDialog(null, "用户  “"+name+"”  ,已被删除成功!");
            } else {
              JOptionPane.showMessageDialog(null, "删除失败!");
            }
            data=select.getTourist("SELECT * FROM tourist");
            dt.setDataVector(data,header);
          }
        }
      }
    });
    JButton btnNewButton_Tip = new JButton("提示");
    btnNewButton_Tip.setBounds(1031, 436, 113, 27);
    btnNewButton_Tip.setFocusPainted(false);//去掉按钮周围的焦点框
    btnNewButton_Tip.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(btnNewButton_Tip);
    btnNewButton_Tip.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(null, "<html>查询:直接点击将列出所有报名信息,也可填写游客编号、团号和性别查询。<br>修改:点击游客将会将游客编号绑定到文本框中,可以对该游客编号对应的游客进行团号和性别修改。<br>删除:点击要删除的信息,点击删除即可。<br>添加:对报名信息进行添加。</html>");
      }
    });
    btnNewButton_Export = new JButton("<html>将数据导出到<br>&ensp;&ensp;Excel 表中</html>");
    btnNewButton_Export.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButtonActionPerformed(e);
      }
    });
    btnNewButton_Export.setBounds(1016, 525, 138, 51);
    btnNewButton_Export.setFocusPainted(false);//去掉按钮周围的焦点框
    btnNewButton_Export.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(btnNewButton_Export);
    //设置单元格内容居中显示
    DefaultTableCellRenderer r = new DefaultTableCellRenderer();   
    r.setHorizontalAlignment(JLabel.CENTER); 
    jTable.setDefaultRenderer(Object.class, r);
  }
  //导出
  private void jButtonActionPerformed(java.awt.event.ActionEvent evt) {
    FileDialog fd = new FileDialog(this, "将数据保存到", FileDialog.SAVE);
    fd.setLocation(1100, 600);
    fd.setVisible(true);
    String stringfile = fd.getDirectory()+fd.getFile()+".xlsx";  
    try {
//    ExcelExporter export = new ExcelExporter();
      this.exportTable(jTable, new File(stringfile));
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
  /**导出JTable到excel */
    public void exportTable(JTable table, File file) throws IOException {
        TableModel model = table.getModel();
        BufferedWriter bWriter = new BufferedWriter(new FileWriter(file));  
        for(int i=0; i < model.getColumnCount(); i++) {
            bWriter.write(model.getColumnName(i));
            bWriter.write("\t");
        }
        bWriter.newLine();
        for(int i=0; i< model.getRowCount(); i++) {
            for(int j=0; j < model.getColumnCount(); j++) {
                bWriter.write(model.getValueAt(i,j).toString());
                bWriter.write("\t");
            }
            bWriter.newLine();
        }
        bWriter.close();
    }
}


RegistrationInfo_Change.Java


package com.ynavc.View;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import com.ynavc.Bean.Tourist;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import com.ynavc.Utils.ValidateUtils;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
public class RegistrationInfo_Change extends JFrame {
  private JTextField textField_name;//姓名
  private JTextField textField_age;//年龄
  private JTextField textField_IDcard;//身份证号码
  private JTextField textField_address;//地址
  private JTextField textField_phone;//电话
  private JTextField textField_th;//团号
  private JTextField textField_pt;//陪同
  private JTextField textField_ss;//食宿
  Select select = new Select();
  Updata updata = new Updata();
  String name,sex,age,Idcard,address,phone,th,pt,ss;
  public RegistrationInfo_Change(Tourist tourist) {
    super("修改报名信息");
    this.setBounds(0, 0, 930, 700);
    this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
    this.setResizable(false);//让窗口大小不可改变
    getContentPane().setLayout(null);
    JLabel lblNewLabel_name= new JLabel("姓名:");
    lblNewLabel_name.setBounds(138, 79, 72, 18);
    getContentPane().add(lblNewLabel_name);
    textField_name = new JTextField();
    textField_name.setBounds(191, 76, 240, 24);
    getContentPane().add(textField_name);
    textField_name.setColumns(10);
    JLabel lblNewLabel_sex= new JLabel("性别:");
    lblNewLabel_sex.setBounds(138, 125, 72, 18);
    getContentPane().add(lblNewLabel_sex);
    JComboBox comboBox_sex= new JComboBox();
    comboBox_sex.setModel(new DefaultComboBoxModel(new String[] {"男", "女"}));
    comboBox_sex.setBounds(191, 122, 240, 24);
    getContentPane().add(comboBox_sex);
    JLabel lblNewLabel_age= new JLabel("年龄:");
    lblNewLabel_age.setBounds(138, 168, 72, 18);
    getContentPane().add(lblNewLabel_age);
    textField_age = new JTextField();
    textField_age.setBounds(191, 165, 240, 24);
    getContentPane().add(textField_age);
    textField_age.setColumns(10);
    JLabel lblNewLabel_IDcard= new JLabel("身份证号码:");
    lblNewLabel_IDcard.setBounds(93, 213, 117, 18);
    getContentPane().add(lblNewLabel_IDcard);
    textField_IDcard = new JTextField();
    textField_IDcard.setBounds(191, 210, 240, 24);
    getContentPane().add(textField_IDcard);
    textField_IDcard.setColumns(10);
    JLabel lblNewLabel_address= new JLabel("住址:");
    lblNewLabel_address.setBounds(138, 254, 72, 18);
    getContentPane().add(lblNewLabel_address);
    textField_address = new JTextField();
    textField_address.setBounds(191, 251, 240, 24);
    getContentPane().add(textField_address);
    textField_address.setColumns(10);
    JLabel lblNewLabel_phone= new JLabel("电话:");
    lblNewLabel_phone.setBounds(138, 295, 72, 18);
    getContentPane().add(lblNewLabel_phone);
    textField_phone = new JTextField();
    textField_phone.setBounds(191, 292, 240, 24);
    getContentPane().add(textField_phone);
    textField_phone.setColumns(10);
    JLabel lblNewLabel_th= new JLabel("团号:");
    lblNewLabel_th.setBounds(138, 335, 72, 18);
    getContentPane().add(lblNewLabel_th);
    textField_th = new JTextField();
    textField_th.setBounds(191, 332, 240, 24);
    getContentPane().add(textField_th);
    textField_th.setColumns(10);
    JLabel lblNewLabel_pt= new JLabel("陪同:");
    lblNewLabel_pt.setBounds(138, 382, 72, 18);
    getContentPane().add(lblNewLabel_pt);
    textField_pt = new JTextField();
    textField_pt.setText("是否选择导游陪同?");
    textField_pt.setToolTipText("");
    textField_pt.setBounds(191, 379, 240, 24);
    getContentPane().add(textField_pt);
    textField_pt.setColumns(10);
    JLabel lblNewLabel_ss= new JLabel("食宿:");
    lblNewLabel_ss.setBounds(138, 427, 72, 18);
    getContentPane().add(lblNewLabel_ss);
    textField_ss = new JTextField();
    textField_ss.setText("是否选择宾馆住宿?");
    textField_ss.setBounds(191, 424, 240, 24);
    getContentPane().add(textField_ss);
    textField_ss.setColumns(10);
    JButton button_1 = new JButton("查看旅游团信息");
    button_1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      }
    });
    button_1.setBounds(453, 331, 158, 27);
    button_1.setFocusPainted(false);//去掉按钮周围的焦点框
    button_1.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_1);
    JButton button_2 = new JButton("显示选择结果");
    button_2.setBounds(625, 331, 146, 27);
    button_2.setFocusPainted(false);//去掉按钮周围的焦点框
    button_2.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_2);
    JButton button_3 = new JButton("是");
    button_3.setBounds(453, 378, 72, 27);
    button_3.setFocusPainted(false);//去掉按钮周围的焦点框
    button_3.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_3);
    button_3.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        textField_pt.setText("是");
      }
    });
    JButton button_4 = new JButton("否");
    button_4.setBounds(539, 378, 72, 27);
    button_4.setFocusPainted(false);//去掉按钮周围的焦点框
    button_4.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_4);
    button_4.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        textField_pt.setText("无");
      }
    });
    JButton button_5 = new JButton("显示选择结果");
    button_5.setBounds(625, 378, 146, 27);
    button_5.setFocusPainted(false);//去掉按钮周围的焦点框
    button_5.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_5);
    JButton button_6 = new JButton("是");
    button_6.setBounds(453, 421, 72, 27);
    button_6.setFocusPainted(false);//去掉按钮周围的焦点框
    button_6.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_6);
    button_6.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        textField_ss.setText("是");
      }
    });
    JButton button_7 = new JButton("否");
    button_7.setBounds(539, 421, 72, 27);
    button_7.setFocusPainted(false);//去掉按钮周围的焦点框
    button_7.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_7);
    button_7.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        textField_ss.setText("无");
      }
    });
    JButton button_8 = new JButton("显示选择结果");
    button_8.setBounds(625, 423, 146, 27);
    button_8.setFocusPainted(false);//去掉按钮周围的焦点框
    button_8.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(button_8);
    textField_name.setText(tourist.getTourist_name());
    String t = tourist.getTourist_sex();
    comboBox_sex.setSelectedItem(t);
    textField_age.setText(tourist.getTourist_age());
    textField_IDcard.setText(tourist.getTourist_idCard());
    textField_address.setText(tourist.getTourist_address());
    textField_phone.setText(tourist.getTourist_phone());
    textField_th.setText(tourist.getGroup_num());
    textField_pt.setText(tourist.getAccompanied());
    textField_ss.setText(tourist.getAccommodation());
    JButton btnNewButton = new JButton("确认修改");
    btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 18));
    btnNewButton.setBounds(388, 516, 124, 33);
    btnNewButton.setFocusPainted(false);//去掉按钮周围的焦点框
    btnNewButton.setContentAreaFilled(false);//设置按钮透明背景
    getContentPane().add(btnNewButton);
    btnNewButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        String id = tourist.getTourist_num();
        name = textField_name.getText();
        sex = comboBox_sex.getSelectedItem().toString();
        age = textField_age.getText();
        Idcard = textField_IDcard.getText();
        address = textField_address.getText();
        phone = textField_phone.getText();
        th = textField_th.getText();
        pt = textField_pt.getText();
        if (pt.equals("是否选择导游陪同?")) {
          pt="无";
        }
        ss = textField_ss.getText();
        if (ss.equals("是否选择宾馆住宿?")) {
          ss="无";
        }
        //判断输入的信息是否为空,是否完整
        if (name.equals("")||sex.equals("")||age.equals("")||Idcard.equals("")||address.equals("")||phone.equals("")||th.equals("")||pt.equals("")||ss.equals("")) {
          JOptionPane.showMessageDialog(null, "请输入完整信息!");
        } else {
          //判断身份证号码
          if (!ValidateUtils.IDcard(Idcard)) {
            JOptionPane.showMessageDialog(null, "身份证号码错误!请检查!");
          } else {
            String i = select.getString("SELECT user_id FROM `user` WHERE user_state='已登录'");
            String sql = "UPDATE tourist SET tourist_name='"+name+"',tourist_sex='"+sex+"',tourist_age='"+age+"',tourist_idcard='"+Idcard+"',tourist_address='"+address+"',tourist_phone='"+phone+"',group_num='"+th+"',accompanied='"+pt+"',accommodation='"+ss+"' WHERE tourist_num='"+id+"';";
            int result = updata.addData(sql);
            //判断手机号
            String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";
                if(phone.length() != 11){
                  JOptionPane.showMessageDialog(null, "手机号应为11位数!");
                }else{
                    Pattern p = Pattern.compile(regex);
                    Matcher m = p.matcher(phone);
                    boolean isMatch = m.matches();
                    if(!isMatch){
                        JOptionPane.showMessageDialog(null, "您的手机号" + phone + "是错误格式!!!");
                    }else {
                      //判断插入结果
                      if (result>0) {
                        JOptionPane.showMessageDialog(null, "修改成功!");
                        Registration_Management r = new Registration_Management();
                  r.dispose();
                  r.setVisible(true);
                  dispose();
                      } else {
                        JOptionPane.showMessageDialog(null, "修改失败,请与管理员联系!");
                      }
              }
                }
          }
        }
      }
    });
  }
}


com.ynavc.Test

Main.java


package com.ynavc.Test;
import com.ynavc.View.MainJframe;
public class Main {
  public static void main(String[] args) {
    MainJframe m = new MainJframe();
    m.setVisible(true);
  }
}
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
24天前
|
NoSQL Java 关系型数据库
Liunx部署java项目Tomcat、Redis、Mysql教程
本文详细介绍了如何在 Linux 服务器上安装和配置 Tomcat、MySQL 和 Redis,并部署 Java 项目。通过这些步骤,您可以搭建一个高效稳定的 Java 应用运行环境。希望本文能为您在实际操作中提供有价值的参考。
115 26
|
28天前
|
JavaScript 安全 Java
java版药品不良反应智能监测系统源码,采用SpringBoot、Vue、MySQL技术开发
基于B/S架构,采用Java、SpringBoot、Vue、MySQL等技术自主研发的ADR智能监测系统,适用于三甲医院,支持二次开发。该系统能自动监测全院患者药物不良反应,通过移动端和PC端实时反馈,提升用药安全。系统涵盖规则管理、监测报告、系统管理三大模块,确保精准、高效地处理ADR事件。
|
2月前
|
关系型数据库 MySQL Java
MySQL索引优化与Java应用实践
【11月更文挑战第25天】在大数据量和高并发的业务场景下,MySQL数据库的索引优化是提升查询性能的关键。本文将深入探讨MySQL索引的多种类型、优化策略及其在Java应用中的实践,通过历史背景、业务场景、底层原理的介绍,并结合Java示例代码,帮助Java架构师更好地理解并应用这些技术。
55 2
|
2月前
|
监控 前端开发 Java
【技术开发】接口管理平台要用什么技术栈?推荐:Java+Vue3+Docker+MySQL
该文档介绍了基于Java后端和Vue3前端构建的管理系统的技术栈及功能模块,涵盖管理后台的访问、登录、首页概览、API接口管理、接口权限设置、接口监控、计费管理、账号管理、应用管理、数据库配置、站点配置及管理员个人设置等内容,并提供了访问地址及操作指南。
|
3月前
|
SQL Java 关系型数据库
java连接mysql查询数据(基础版,无框架)
【10月更文挑战第12天】该示例展示了如何使用Java通过JDBC连接MySQL数据库并查询数据。首先在项目中引入`mysql-connector-java`依赖,然后通过`JdbcUtil`类中的`main`方法实现数据库连接、执行SQL查询及结果处理,最后关闭相关资源。
233 6
|
3月前
|
SQL JavaScript 关系型数据库
node博客小项目:接口开发、连接mysql数据库
【10月更文挑战第14天】node博客小项目:接口开发、连接mysql数据库
|
8天前
|
Java
Java—多线程实现生产消费者
本文介绍了多线程实现生产消费者模式的三个版本。Version1包含四个类:`Producer`(生产者)、`Consumer`(消费者)、`Resource`(公共资源)和`TestMain`(测试类)。通过`synchronized`和`wait/notify`机制控制线程同步,但存在多个生产者或消费者时可能出现多次生产和消费的问题。 Version2将`if`改为`while`,解决了多次生产和消费的问题,但仍可能因`notify()`随机唤醒线程而导致死锁。因此,引入了`notifyAll()`来唤醒所有等待线程,但这会带来性能问题。
Java—多线程实现生产消费者
|
10天前
|
安全 Java Kotlin
Java多线程——synchronized、volatile 保障可见性
Java多线程中,`synchronized` 和 `volatile` 关键字用于保障可见性。`synchronized` 保证原子性、可见性和有序性,通过锁机制确保线程安全;`volatile` 仅保证可见性和有序性,不保证原子性。代码示例展示了如何使用 `synchronized` 和 `volatile` 解决主线程无法感知子线程修改共享变量的问题。总结:`volatile` 确保不同线程对共享变量操作的可见性,使一个线程修改后,其他线程能立即看到最新值。
|
10天前
|
消息中间件 缓存 安全
Java多线程是什么
Java多线程简介:本文介绍了Java中常见的线程池类型,包括`newCachedThreadPool`(适用于短期异步任务)、`newFixedThreadPool`(适用于固定数量的长期任务)、`newScheduledThreadPool`(支持定时和周期性任务)以及`newSingleThreadExecutor`(保证任务顺序执行)。同时,文章还讲解了Java中的锁机制,如`synchronized`关键字、CAS操作及其实现方式,并详细描述了可重入锁`ReentrantLock`和读写锁`ReadWriteLock`的工作原理与应用场景。
|
11天前
|
安全 Java 编译器
深入理解Java中synchronized三种使用方式:助您写出线程安全的代码
`synchronized` 是 Java 中的关键字,用于实现线程同步,确保多个线程互斥访问共享资源。它通过内置的监视器锁机制,防止多个线程同时执行被 `synchronized` 修饰的方法或代码块。`synchronized` 可以修饰非静态方法、静态方法和代码块,分别锁定实例对象、类对象或指定的对象。其底层原理基于 JVM 的指令和对象的监视器,JDK 1.6 后引入了偏向锁、轻量级锁等优化措施,提高了性能。
33 3