基于java+mysql的swing+mysql火车票售票管理系统(java+swing+mysql+gui)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
管理员管理车票和用户、用户购买车票等
技术框架
Java Swing MySQL
基于java+mysql的Swing+MySQL火车票售票管理系统(java+swing+mysql+gui)
ticket.getTicket_office()
});
}
}
public void del() throws SQLException {
if (table.getSelectedRowCount() <= 0) {
JOptionPane.showMessageDialog(null, "请选择要删除的数据行");
return;
}
int result = JOptionPane.showConfirmDialog(null, "是否确定要删除");
// 判断用户是否点击
if (result == JOptionPane.OK_OPTION) {
int ticketid = Integer.valueOf(table.getValueAt(
table.getSelectedRow(), 0).toString());
ticketDao.delete(ticketid);
loadData();
}
}
public void updata() throws SQLException {
if (table.getSelectedRowCount() <= 0) {
JOptionPane.showMessageDialog(null, "请选择要修改的数据行");
return;
}
int result = JOptionPane.showConfirmDialog(null, "是否确定要修改");
// 判断用户是否点击
if (result == JOptionPane.OK_OPTION) {
int ticketid = Integer.valueOf(table.getValueAt(table.getSelectedRow(), 0).toString());
String station_arrival = table.getValueAt(table.getSelectedRow(), 1).toString();
String station_depart = table.getValueAt(table.getSelectedRow(), 2).toString();
String depart_date = table.getValueAt(table.getSelectedRow(), 3).toString();
String depart_time = table.getValueAt(table.getSelectedRow(), 4).toString();
int ticket_number = Integer.valueOf(table.getValueAt(table.getSelectedRow(), 5).toString());
String seattypeid = table.getValueAt(table.getSelectedRow(), 6).toString();
String tickettypeid = table.getValueAt(table.getSelectedRow(), 7).toString();
int tickets_left = Integer.valueOf(table.getValueAt(table.getSelectedRow(), 8).toString());
String fares = table.getValueAt(table.getSelectedRow(), 9).toString();
String ticket_office = table.getValueAt(table.getSelectedRow(), 10).toString();
Ticket ticket = new Ticket(ticketid, station_arrival, station_depart, depart_date, depart_time,
ticket_number, seattypeid, tickettypeid, tickets_left, fares, ticket_office);
UpdataTicket updataticket = new UpdataTicket(ticket);
updataticket.setVisible(true);
}
}
public void setUserticketticket_office(String userticketticket_office) {
this.userticketticket_office = userticketticket_office;
}
@Override
public String toString() {
return "Userticket [userticketid=" + userticketid + ", userticketuserid=" + userticketuserid
+ ", userticketticketid=" + userticketticketid + ", userticketname=" + userticketname
+ ", userticketidentity_number=" + userticketidentity_number + ", userticketstation_arrival="
+ userticketstation_arrival + ", userticketstation_depart=" + userticketstation_depart
+ ", userticketdepart_date=" + userticketdepart_date + ", userticketdepart_time="
+ userticketdepart_time + ", userticketticket_number=" + userticketticket_number
+ ", userticketseattype=" + userticketseattype + ", usertickettickettype=" + usertickettickettype
+ ", userticketfares=" + userticketfares + ", userticketticket_office=" + userticketticket_office + "]";
}
public UserTicket(int userticketid, int userticketuserid, int userticketticketid, String userticketname,
String userticketidentity_number, String userticketstation_arrival, String userticketstation_depart,
String userticketdepart_date, String userticketdepart_time, int userticketticket_number,
String userticketseattype, String usertickettickettype, String userticketfares,
String userticketticket_office) {
super();
this.userticketid = userticketid;
this.userticketuserid = userticketuserid;
this.userticketticketid = userticketticketid;
this.userticketname = userticketname;
this.userticketidentity_number = userticketidentity_number;
this.userticketstation_arrival = userticketstation_arrival;
this.userticketstation_depart = userticketstation_depart;
this.userticketdepart_date = userticketdepart_date;
this.userticketdepart_time = userticketdepart_time;
this.userticketticket_number = userticketticket_number;
this.userticketseattype = userticketseattype;
this.usertickettickettype = usertickettickettype;
this.userticketfares = userticketfares;
this.userticketticket_office = userticketticket_office;
}
}
return;
} else if (txtticket_number.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入车次", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txttickets_left.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入余票", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtfares.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入票价", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtticket_office.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入发售站", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
}
int ticketid = ticket.getTicketid();
String station_arrival = txtstation_arrival.getText();
String station_depart = txtstation_depart.getText();
String depart_date = txtdepart_date.getText();
String depart_time = txtdepart_time.getText();
String ticket_number0 = txtticket_number.getText();
int ticket_number = Integer.parseInt(ticket_number0);
Seattype seattype = (Seattype) cmbseattype.getSelectedItem();
String seattypeid = String.valueOf(seattype.getSeattypename()).toString();
Tickettype tickettype = (Tickettype) cmbtickettype.getSelectedItem();
String tickettypeid = String.valueOf(tickettype);
String tickets_left0 = txttickets_left.getText();
int tickets_left = Integer.parseInt(tickets_left0);
String fares = txtfares.getText();
String ticket_office = txtticket_office.getText();
Ticket ticket = new Ticket(ticketid, station_arrival, station_depart,
depart_date, depart_time, ticket_number, seattypeid,
tickettypeid, tickets_left, fares, ticket_office);
boolean flag;
try {
flag = ticketDao.update(ticket);
if (flag) {
JOptionPane.showMessageDialog(null, "修改成功");
dispose();
} else {
JOptionPane.showMessageDialog(null, "修改失败");
}
} catch (Exception e) {
// TODO Auto-generated catch block
}
// 更新数据
int ticketid = Integer.valueOf(table.getValueAt(e.getLastRow(), 0).toString());
String station_arrival = table.getValueAt(e.getLastRow(), 1).toString();
String station_depart = table.getValueAt(e.getLastRow(), 2).toString();
String depart_date = table.getValueAt(e.getLastRow(), 3).toString();
String depart_time = table.getValueAt(e.getLastRow(), 4).toString();
int ticket_number = Integer.valueOf(table.getValueAt(e.getLastRow(), 5).toString());
String seattype = table.getValueAt(e.getLastRow(), 6).toString();
String tickettype = table.getValueAt(e.getLastRow(), 7).toString();
int tickets_left = Integer.valueOf(table.getValueAt(e.getLastRow(), 8).toString());
String fares = table.getValueAt(e.getLastRow(), 9).toString();
String ticket_office = table.getValueAt(e.getLastRow(), 10).toString();
Ticket ticket = new Ticket(ticketid, station_arrival, station_depart, depart_date, depart_time, ticket_number
, seattype, tickettype, tickets_left, fares, ticket_office);
try {
ticketimpl.update(ticket);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
loadData();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
public void loadData() throws SQLException {
// 清除旧的数据
model.getDataVector().clear();
List<Ticket> list = ticketDao.queryAll();
// 遍历每一条数据,添加到model中
for (Ticket ticket : list) {
txtstation_arrival.setBounds(350, 65, 146, 23);
add(txtstation_arrival);
txtstation_arrival.setColumns(10);
JLabel label1 = new JLabel("乘车站:");
label1.setBounds(280, 97, 146, 23);
add(label1);
txtstation_depart = new JTextField();
txtstation_depart.setBounds(350, 97, 146, 23);
add(txtstation_depart);
txtstation_arrival.setColumns(10);
JLabel label_20 = new JLabel("发车日期:");
label_20.setBounds(280, 130, 146, 23);
add(label_20);
txtdepart_date = new JTextField();
txtdepart_date.setBounds(350, 130, 146, 23);
add(txtdepart_date);
txtdepart_date.setColumns(10);
JLabel label_2 = new JLabel("发车时间:");
label_2.setBounds(280, 162, 146, 23);
add(label_2);
txtdepart_time = new JTextField();
txtdepart_time.setBounds(350, 162, 146, 23);
add(txtdepart_time);
txtdepart_time.setColumns(10);
JLabel label_3 = new JLabel("车次(整数):");
label_3.setBounds(280, 195, 146, 23);
add(label_3);
txtticket_number = new JTextField();
txtticket_number.setBounds(350, 195, 146, 23);
add(txtticket_number);
txtticket_number.setColumns(10);
JLabel label_4 = new JLabel("车票余量:");
label_4.setBounds(280, 227, 146, 23);
add(label_4);
txttickets_left = new JTextField();
txttickets_left.setBounds(350, 227, 146, 23);
}
/**
* 车票实体
*/
public class Ticket implements Serializable {
private int ticketid;
private String station_arrival;
private String station_depart;
private String depart_date;
private String depart_time;
private int ticket_number;
private String seattypeid;
private String tickettypeid;
private int tickets_left;
private String fares;
private String ticket_office;
public int getTicketid() {
return ticketid;
}
public void setTicketid(int ticketid) {
this.ticketid = ticketid;
}
public String getStation_arrival() {
return station_arrival;
}
public void setStation_arrival(String station_arrival) {
this.station_arrival = station_arrival;
}
public String getStation_depart() {
return station_depart;
}
}
});
btnNewButton.setBounds(320, 480, 146, 23);
add(btnNewButton);
}
//public static void main(String[] args) {
//AddTicket s= new AddTicket();
//System.out.println(s.cmbtickettype.getSelectedItem());
// }
}
public class Userbuy_db extends JPanel {
private JTable table;
private DefaultTableModel model;// 用于存储表格数据
private String oldValue = "";// 保存单元格编辑 前的值
private TickeDao ticketDao;
private TickeDao ticketim;
textname = c;
}
public void setidentity_numberField(JTextField f) {
textidentity_number = f;
}
public void setokButton(JButton b1) {
okButton = b1;
}
public void setresetButton(JButton b2) {
resetButton = b2;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == okButton) {
if (textacc.getText().equals("")) //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入账号", "警告对话框", JOptionPane.WARNING_MESSAGE);
else if (textpass.getText().equals(""))
JOptionPane.showMessageDialog(null, "请输入密码", "警告对话框", JOptionPane.WARNING_MESSAGE);
else if (textname.getText().equals(""))
JOptionPane.showMessageDialog(null, "请输入姓名", "警告对话框", JOptionPane.WARNING_MESSAGE);
else if (textidentity_number.getText().equals(""))
JOptionPane.showMessageDialog(null, "请输入身份证号", "警告对话框", JOptionPane.WARNING_MESSAGE);
else {
String acc = textacc.getText();
String pass = textpass.getText();
String name = textname.getText();
String identity_number = textidentity_number.getText();
if (acc.trim().length() < 1) {
JOptionPane.showMessageDialog(null, "账号必须大于0位!");
return;
}
if (pass.trim().length() < 1) {
JOptionPane.showMessageDialog(null, "密码必须大于0位!");
return;
}
public void delete(int userid) throws SQLException {
Connection con = Util.getConnection();
String sqladd = "delete from user where userid=?";
PreparedStatement stmt = con.prepareStatement(sqladd);
stmt.setInt(1, userid);
ResultSet rs = null;
stmt.executeUpdate();
Util.closeAll(con, stmt, rs);
}
public List<User> QueryById(int userid) throws SQLException {
Connection con = Util.getConnection();
String sqladd = "select * from user where userid=?";
PreparedStatement stmt = con.prepareStatement(sqladd);
stmt.setInt(1, userid);
ResultSet rs = stmt.executeQuery();
List<User> user = new ArrayList<>();
while (rs.next()) {
int userid0 = rs.getInt(1);
String name = rs.getString(2);
String identity_number = rs.getString(3);
String account = rs.getString(4);
String password = rs.getString(5);
User user0 = new User(userid0, name, identity_number, account, password);
user.add(user0);
}
Util.closeAll(con, stmt, rs);
return user;
}
public List<User> queryAll() throws SQLException {
Connection con = Util.getConnection();
String sqladd = "select * from user";
PreparedStatement stmt = con.prepareStatement(sqladd);
ResultSet rs = stmt.executeQuery();
List<User> user = new ArrayList<>();
while (rs.next()) {
int userid0 = rs.getInt(1);
String name = rs.getString(2);
String identity_number = rs.getString(3);
String account = rs.getString(4);
String password = rs.getString(5);
User user0 = new User(userid0, name, identity_number, account, password);
user.add(user0);
}
Util.closeAll(con, stmt, rs);
return user;
}
public void setTicketid(int ticketid) {
this.ticketid = ticketid;
}
public String getStation_arrival() {
return station_arrival;
}
public void setStation_arrival(String station_arrival) {
this.station_arrival = station_arrival;
}
public String getStation_depart() {
return station_depart;
}
public void setStation_depart(String station_depart) {
this.station_depart = station_depart;
}
public String getDepart_date() {
return depart_date;
}
public void setDepart_date(String depart_date) {
this.depart_date = depart_date;
}
public String getDepart_time() {
return depart_time;
}
public void setDepart_time(String depart_time) {
this.depart_time = depart_time;
}
public int getTicket_number() {
return ticket_number;
}
public void setTicket_number(int ticket_number) {
this.ticket_number = ticket_number;
}
public String getSeattypeid() {
return seattypeid;
}
public void setSeattypeid(String seattypeid) {
this.seattypeid = seattypeid;
}
private JTextField txtPassword;
private UserDaoImpl userDao;
/**
* Create the panel.
*/
public AddUser() {
setLayout(null);
JLabel label = new JLabel("用户姓名:");
label.setBounds(250, 100, 70, 23);
add(label);
txtname = new JTextField();
txtname.setBounds(350, 100, 180, 23);
add(txtname);
txtname.setColumns(10);
JLabel label_1 = new JLabel("证件号码");
label_1.setBounds(250, 170, 70, 23);
add(label_1);
txtidentity_number = new JTextField();
txtidentity_number.setBounds(350, 170, 180, 23);
add(txtidentity_number);
txtidentity_number.setColumns(10);
JLabel label_2 = new JLabel("账号");
label_2.setBounds(250, 240, 70, 23);
add(label_2);
txtaccout = new JTextField();
txtaccout.setBounds(350, 240, 180, 23);
add(txtaccout);
txtaccout.setColumns(10);
JLabel label_3 = new JLabel("密码");
label_3.setBounds(250, 310, 70, 23);
add(label_3);
txtPassword = new JTextField();
txtPassword.setBounds(350, 310, 180, 23);
add(txtPassword);
txtPassword.setColumns(10);
userDao = new UserDaoImpl();
JButton btnNewButton = new JButton("添加用户");
public boolean buyTicketb(int ticketid, int userid) throws Exception {
Connection conn = Util.getConnection();
String sqladd = "select * from user,ticket where userid = ? and ticketid=?";
PreparedStatement stmt = conn.prepareStatement(sqladd);
stmt.setInt(1, userid);
stmt.setInt(2, ticketid);
ResultSet rt = stmt.executeQuery();
System.out.println(rt);
System.out.println(ticketid + "+++" + userid);
while (rt.next()) {
int userticketuserid = rt.getInt(1);
String userticketname = rt.getString(2);
String userticketidentity_number = rt.getString(3);
String ac = rt.getString(4);
String ps = rt.getString(5);
int bl = rt.getInt(6);
int userticketticketid = rt.getInt(7);
String userticketstation_arrival = rt.getString(8);
String userticketstation_depart = rt.getString(9);
String userticketdepart_date = rt.getString(10);
String userticketdepart_time = rt.getString(11);
int userticketticket_number = rt.getInt(12);
String userticketseattype = rt.getString(13);
String usertickettickettype = rt.getString(14);
int left = rt.getInt(15);
String userticketfares = rt.getString(16);
String userticketticket_office = rt.getString(17);
System.out.println(userid + userticketdepart_date + ac + ps + left + bl);
add(userticketuserid, userticketticketid, userticketname,
userticketidentity_number, userticketstation_arrival,
userticketstation_depart, userticketdepart_date,
userticketdepart_time, userticketticket_number, userticketseattype,
usertickettickettype, userticketfares, userticketticket_office);
}
Util.closeAll(conn, stmt, rt);
return true;
}
userDao.update(user);
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
}
public void loadData() {
// 清除旧的数据
model.getDataVector().clear();
// 查询部门数据
//TableColumnModel col = table.getColumnModel();
// 获取部门的列,设置这个列为下拉框列类型
List<User> list;
try {
list = userDao.queryAll();
// 遍历每一条数据,添加到model中
for (User user : list) {
// 添加 行数据
model.addRow(new Object[]{user.getUserid(), user.getName(),
user.getIdentity_number(), user.getAccount(), user.getPassword()});
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public void del() throws SQLException {
if (table.getSelectedRowCount() <= 0) {
JOptionPane.showMessageDialog(null, "请选择要删除的数据行");
return;
}
int result = JOptionPane.showConfirmDialog(null, "是否确定要删除");
// 判断用户是否点击
if (result == JOptionPane.OK_OPTION) {
int userid = Integer.valueOf(table.getValueAt(
table.getSelectedRow(), 0).toString());
userDao.delete(userid);
loadData();
}
}
public void updata() {
if (table.getSelectedRowCount() <= 0) {
JOptionPane.showMessageDialog(null, "请选择要修改的数据行");
return;
}
int result = JOptionPane.showConfirmDialog(null, "是否确定要修改");
// 判断用户是否点击
if (result == JOptionPane.OK_OPTION) {
ResultSet rr = null;
System.out.println(sql);
if (result >= 1) {
flag = true;
}
Util.closeAll(con, stmt, rr);
return flag;
}
@Override
public boolean reduBlance(int userid, int yuan) throws SQLException {
System.out.println(userid + "+++++" + yuan);
boolean flag = false;
String sql = "update user set balance=balance-? where userid = ?";
Connection con = Util.getConnection();
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setInt(1, yuan);
stmt.setInt(2, userid);
int result = stmt.executeUpdate();
ResultSet rr = null;
System.out.println(sql);
if (result >= 1) {
flag = true;
}
Util.closeAll(con, stmt, rr);
return flag;
}
@Override
public int selectbl(int userid) throws SQLException {
Connection con = Util.getConnection();
int far = 0;
String sqladd = "select balance from user where userid=? ";
PreparedStatement stmt = con.prepareStatement(sqladd);
stmt.setInt(1, userid);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
far = rs.getInt(1);
}
return far;
}
}
public class UpdataTicket extends JFrame {
JPanel contentPane;
private JTextField txtstation_arrival;
private JTextField txtstation_depart;
private JTextField txtdepart_date;
private JTextField txtdepart_time;
private JTextField txtticket_number;
private JTextField txttickets_left;
private JTextField txtfares;
private JTextField txtticket_office;
private JComboBox cmbtickettype;
private JComboBox cmbseattype;
private TickeDao ticketDao;
private TickettypeImpl tickettypeDao;
private SeattypeImpl seattypeDao;
/**
* Create the panel.
*
* @param tickettypeDao
* @throws SQLException
*/
public UpdataTicket(Ticket ticket) throws SQLException {
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(500, 100, 800, 800);
contentPane = new JPanel();
JLabel label = new JLabel("到达站:");
label.setBounds(280, 65, 146, 23);
add(label);
txtstation_arrival = new JTextField();
txtstation_arrival.setBounds(350, 65, 146, 23);
add(txtstation_arrival);
txtstation_arrival.setColumns(10);
txtstation_arrival.setText(ticket.getStation_arrival());
JLabel label1 = new JLabel("乘车站:");
label1.setBounds(280, 97, 146, 23);
add(label1);
txtstation_depart = new JTextField();
txtstation_depart.setBounds(350, 97, 146, 23);
add(txtstation_depart);
txtstation_depart.setColumns(10);
txtidentity_number = new JTextField();
txtidentity_number.setBounds(350, 170, 180, 23);
add(txtidentity_number);
txtidentity_number.setColumns(10);
txtidentity_number.setText(user.getIdentity_number());
JLabel label_2 = new JLabel("账号");
label_2.setBounds(250, 240, 70, 23);
add(label_2);
txtaccout = new JTextField();
txtaccout.setBounds(350, 240, 180, 23);
add(txtaccout);
txtaccout.setColumns(10);
txtaccout.setText(user.getAccount());
JLabel label_3 = new JLabel("密码");
label_3.setBounds(250, 310, 70, 23);
add(label_3);
txtPassword = new JTextField();
txtPassword.setBounds(350, 310, 180, 23);
add(txtPassword);
txtPassword.setColumns(10);
txtPassword.setText(user.getPassword());
userDao = new UserDaoImpl();
JButton btnNewButton = new JButton("修改用户");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (txtname.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入姓名", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (txtidentity_number.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入身份证号", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (txtaccout.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入账号", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (txtPassword.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入密码", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
}
try {
boolean flag;
JLabel label_6 = new JLabel("座位类型:");
label_6.setBounds(280, 292, 146, 23);
add(label_6);
cmbseattype = new JComboBox(list1.toArray());
cmbseattype.setBounds(350, 292, 146, 23);
add(cmbseattype);
JLabel label_7 = new JLabel("车票价格:");
label_7.setBounds(280, 325, 146, 23);
add(label_7);
txtfares = new JTextField();
txtfares.setBounds(350, 325, 146, 23);
add(txtfares);
txtfares.setColumns(10);
txtfares.setText(ticket.getFares());
JLabel label_8 = new JLabel("发售站:");
label_8.setBounds(280, 357, 146, 23);
add(label_8);
txtticket_office = new JTextField();
txtticket_office.setBounds(350, 357, 146, 23);
add(txtticket_office);
txtticket_office.setColumns(10);
txtticket_office.setText(ticket.getTicket_office());
ticketDao = new TicketImpl();
JButton btnNewButton = new JButton("修改车票");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (txtstation_arrival.getText().equals("")) { //判断用户输入是否为空;
JOptionPane.showMessageDialog(null, "请输入到达站", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtstation_depart.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入乘车站", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtdepart_date.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入发车日期", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
} else if (txtdepart_time.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入发车时间", "警告对话框", JOptionPane.WARNING_MESSAGE);
return;
private UserTicketDao usertickrtdao;
private UserDao userdao;
private TickeDao ticketdao;
JPanel contentPane;
JPanel contentPane4;
JPanel panelBottom;
public String sql;
Statement stmt;
public User_user_db() {
setLayout(new BorderLayout(0, 0));
JScrollPane scrollPane = new JScrollPane();
add(scrollPane, BorderLayout.CENTER);
table = new JTable();
scrollPane.setColumnHeaderView(table);
// 初始化存储表格数据的对象
model = new DefaultTableModel(new Object[][]{}, new String[]{"编号", "票号", "用户编号", "姓名", "身份证号",
"到达站", "出发站", "发车日期", "发车时间", "车次", "座位类型", "机车类型", "票价", "售票站"});
// 将数据绑定到对象中
table.setModel(model);
table.setRowHeight(30);
scrollPane.setViewportView(table);
try {
loadData();
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
public void loadData() throws SQLException {
// 清除旧的数据
model.getDataVector().clear();