火车订票系统

  • X0_545462
    了解作者
  • 1.8MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-14 02:53
    上传日期
c/s系统,基于socket的火车订票系统。界面较简单。。数据库用的是mysql,如果需要改变请自己改变
工程实践.rar
  • 工程实践
  • bin
  • images
  • background.jpg
    201KB
  • train.jpg
    10.6KB
  • haha.jpg
    334.7KB
  • 123.jpg
    325.7KB
  • Conn_sql
  • Conn.class
    8KB
  • Window
  • AdminManage$1.class
    647B
  • DeleteUser$1.class
    771B
  • AddTrain$3.class
    769B
  • Adduser.class
    3.4KB
  • Login$3.class
    591B
  • InquriyUser.class
    2.2KB
  • Inquiry.class
    5KB
  • Inquiry$2.class
    2.2KB
  • DeleteUser$2.class
    2.5KB
  • MainWindow$2.class
    719B
  • DeleteTicket.class
    4.1KB
  • BookWindow$3.class
    2KB
  • MainWindow.class
    3.5KB
  • BookWindow$2.class
    1.8KB
  • Inquiry$1.class
    634B
  • DeleteTicket$1.class
    672B
  • Adduser$2.class
    638B
  • AddTrain$2.class
    3.2KB
  • Ticket.class
    1.8KB
  • DeleteTicket$3.class
    727B
  • Login$2.class
    634B
  • InputStartEnd$1.class
    1.4KB
  • BookWindow$1.class
    716B
  • Login$1.class
    1.5KB
  • refund$2.class
    648B
  • InputStartEnd.class
    2KB
  • MainWindow$1.class
    716B
  • DeleteUser.class
    3.2KB
  • DeleteTicket$2.class
    829B
  • DeleteUser$3.class
    744B
  • MainWindow$3.class
    715B
  • Adduser$1.class
    1.4KB
  • Inquiry$3.class
    2KB
  • BookWindow.class
    3.4KB
  • AddTrain.class
    5KB
  • AddTrain$1.class
    648B
  • refund.class
    3.2KB
  • Login.class
    2.8KB
  • refund$1.class
    2.6KB
  • AdminManage.class
    2.6KB
  • Model
  • NumberCombobBoxModel.class
    1KB
  • NumberListModel.class
    968B
  • ResultSetTableModel.class
    1.8KB
  • .settings
  • org.eclipse.jdt.core.prefs
    629B
  • src
  • images
  • background.jpg
    201KB
  • train.jpg
    10.6KB
  • haha.jpg
    334.7KB
  • 123.jpg
    325.7KB
  • Conn_sql
  • Conn.java
    8KB
  • Window
  • Inquiry.java
    4KB
  • refund.java
    2.5KB
  • AddTrain.java
    5.2KB
  • InquriyUser.java
    1.2KB
  • MainWindow.java
    3KB
  • Login.java
    3KB
  • AdminManage.java
    1.7KB
  • Ticket.java
    1.5KB
  • InputStartEnd.java
    2.1KB
  • DeleteUser.java
    2.6KB
  • Adduser.java
    2.9KB
  • DeleteTicket.java
    2.8KB
  • BookWindow.java
    4.1KB
  • Model
  • NumberListModel.java
    671B
  • ResultSetTableModel.java
    1.4KB
  • NumberCombobBoxModel.java
    624B
  • .project
    388B
  • .classpath
    368B
内容介绍
package Conn_sql; import java.sql.*; import javax.swing.JOptionPane; import Window.Ticket; import com.mysql.jdbc.Driver; public class Conn { private static final String DRIVER = "com.mysql.jdbc.Driver"; private static final String URL = "jdbc:mysql://localhost:3306/trainticket"; private static final String USER = "root"; private static final String PASSWORD = "cxzhy0909"; private Connection conn; private PreparedStatement ps; private ResultSet rs; public Conn() { try { Class.forName("com.mysql.jdbc.Driver"); ////加载数据库驱动 conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/trainticket","root","cxzhy0909"); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } //是否为管理员 public boolean ifAdmin(String name, String password) { String sql = "select * from administrator where name = ? and password = ?" ; boolean b = false; try{ ps = conn.prepareStatement(sql); ps.setString(1,name); ps.setString(2,password); rs = ps.executeQuery(); if(rs.next()) { b = true; }else{ b = false; } }catch(SQLException e){ System.out.println (e.getMessage()); } return b; } //是否为用户 public boolean ifuser(String name, String password) { String sql = "select * from user where name = ? and password = ?" ; boolean b = false; try{ ps = conn.prepareStatement(sql); ps.setString(1,name); ps.setString(2,password); rs = ps.executeQuery(); if(rs.next()) { b = true; }else{ b = false; } }catch(SQLException e){ System.out.println (e.getMessage()); } return b; } //关闭连接 public void close() { if(conn == null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } //判断是否已注册 public boolean haslogin(String name) { String sql = "select * from user where name = ?" ; boolean b = false; try{ ps = conn.prepareStatement(sql); ps.setString(1,name); rs = ps.executeQuery(); if(rs.next()) { b = true; }else{ b = false; } }catch(SQLException e){ System.out.println (e.getMessage()); } return b; } //添加用户 public void insertUser(String name, String bankCard, String password, String ID) { String sql = "insert into user values (?,?,?,?)"; try { ps = conn.prepareStatement(sql); ps.setString(1, name); ps.setString(2, bankCard); ps.setString(3, password); ps.setString(4, ID); if(ps.executeUpdate()!=1) { JOptionPane.showMessageDialog(null, "注册失败", "出错了", JOptionPane.ERROR_MESSAGE); } else{ sql="create table " +name+ "(" + "ID varchar(10) primary key," + "startPoint varchar(20)," + "destination varchar(30)," + "price float," + "startTime datetime" + ")"; try { ps = conn.prepareStatement(sql); ps.execute(); }catch(SQLException e){ System.out.println (e.getMessage()); } JOptionPane.showMessageDialog(null, "注册成功","恭喜", JOptionPane.WARNING_MESSAGE); } } catch (SQLException e) { e.printStackTrace(); } } //用户按车次查询火车票 public ResultSet inquiryID(String ID) { String sql = "select * from ticket where ID = ?"; boolean b = false; try{ ps = conn.prepareStatement(sql); ps.setString(1,ID); rs = ps.executeQuery(); }catch(SQLException e){ System.out.println (e.getMessage()); } return rs; } public ResultSet inquiryDesStar(String startPoint, String destination) { String sql = "select * from ticket where startPoint = ? and destination= ?"; try{ ps = conn.prepareStatement(sql); ps.setString(1, startPoint); ps.setString(2, destination); rs = ps.executeQuery(); }catch(SQLException e){ System.out.println (e.getMessage()); } return rs; } public ResultSet sureBook(String ID) { String sql = "select * from ticket where ID = ?"; boolean b = false; try{ ps = conn.prepareStatement(sql); ps.setString(1, ID); rs = ps.executeQuery(); }catch(SQLException e){ System.out.println (e.getMessage()); } return rs; } public void book(String ID) { String sql = "update ticket set restNum =restNum-1 where ID = ?"; boolean b = false; try{ ps = conn.prepareStatement(sql); ps.setString(1, ID); if(ps.executeUpdate() == 1) { JOptionPane.showMessageDialog(null, "订票成功","恭喜", JOptionPane.INFORMATION_MESSAGE); } else JOptionPane.showMessageDialog(null, "no", "警告", JOptionPane.ERROR_MESSAGE); }catch(SQLException e){ System.out.println (e.getMessage()); } } //订票后记录 public void addbuy(String user,Ticket tk) { String sql = "insert into " +user+ " values (?,?,?,?,?)"; try{ ps = conn.prepareStatement(sql); ps.setString(1,tk.getID()); ps.setString(2, tk.getStartPoint()); ps.setString(3, tk.getDestination()); ps.setString(4, String.valueOf(tk.getPrice())); ps.setString(5, tk.getDateTime()); ps.executeUpdate(); }catch(SQLException e){ System.out.println (e.getMessage()); } } public ResultSet gethasBuy(String user) { String sql = "select * from "+user; try{ ps = conn.prepareStatement(sql); rs = ps.executeQuery(); }catch(SQLException e){ System.out.println (e.getMessage()); } return rs; } public void refund(String ID,String user) { String sql1 = "update ticket set restNum =restNum+1 where ID = ?"; String sql2 = "delete from "+user+" where ID = ?"; try { ps = conn.prepareStatement(sql1); ps.setString(1,ID); ps.execute(); ps = conn.prepareStatement(sql2); ps.setString(1,ID); ps.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //管理员查找用户 public ResultSet administratorDelete() { ResultSet rs=null; String sql = "select * from user "; try { ps = conn.prepareStatement(sql); rs = ps.executeQuery(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return rs; } //删除用户 public void delUser(String name) { String sql1 = "delete from user where name = ?"; String sql2 = "drop table "+name; try{ ps = conn.prepareStatement(sql1); ps.setString(1,name); ps.execute(); ps = conn.prepareStatement(sql2); ps.execute(); }catch(SQLException e){ System.out.println (e.getMessage()); } } public void addTicket(Ticket ticket) { String sql = "insert into ticket"+ " values (?,?,?,?,?,?)"; try{ ps = conn.prepareStatement(sql); ps.setString(1, ticket.getID()); ps.setString(2, ticket.getStartPoint()); ps.setString(3, ticket.getDestination()); ps.setString(4, String.valueOf(ticket.getPrice())); ps.setString(5, String.valueOf(ticket.getRestNumber())); ps.setString(6, ticket.getDateTime()); ps.executeUpdate(); }catch(SQLException e){ System.out.println (e.getMessage()); } } public ResultSet updateTicket(String dateTime) { String sql = "select * from ticket Where startTime < ?"; try{ ps = conn.prepareStatement(sql); ps.setString(1, dateTime); rs = ps.executeQuery(); }catch(SQLException e){ System.out.println (e.getMessage()); } return rs; } public void delTicket(String Id) { String sql1 = "delete from ticket where Id = ?"; try{ ps =
评论
    相关推荐