• 大小: 50KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-21
  • 语言: Java
  • 标签: 火车  

资源简介

火车票管理系统,java编写的火车票管理系统,写的不错就是没有做数据库

资源截图

代码片段和文件信息

package trainticket;

import java.sql.*;
import javax.swing.JOptionPane;

/**
 * 

title: 


 *
 * 

Description: 


 *
 * 

Copyright: Copyright (c) 2007


 *
 * 

Company: 


 *
 * @author not attributable
 * @version 1.0
 */
public class DB {

    frame1 frm = new frame1();
    public DB(frame1 frm) {
        this.frm = frm;
    }

//得到连接
    public Connection getcon() {
        Connection con = null;
        String url = null;
        try {
            Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver“);
            url = “jdbc:odbc:netbar“;
            con = DriverManager.getConnection(url);
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return con;
    }

//关闭连接
    public void close(Connection con) {
        try {
            con.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

//查找车次一系列判断
    public boolean find(TicketBean tb) {

        Connection con = this.getcon();
        //判断数据库是否连接
        if (con == null) {
            JOptionPane.showMessageDialog(frm “数据库连接失败“);
            return false;
        }
        //是否输入车次
        if (frm.TrainNum.getText() == null ||
            frm.TrainNum.getText().length() <= 0) {
            JOptionPane.showMessageDialog(frm “请输入车次“);
            return false;
        }
        //是否选择乘车方式
        if (frm.RaidaoHard.isSelected() == false && frm.RadioSoft.isSelected() == false) {
            JOptionPane.showMessageDialog(frm “请选择乘车方式“);
            return false;
        }
        //是否填写购买数量
        if (frm.OrderNum.getText() == null ||
            frm.OrderNum.getText().length() <= 0) {
            JOptionPane.showMessageDialog(frm “请填写购买数量“);
            return false;
        }
        //数据库结果集里rs.*只能被调用一次,所以为了多次调用而把rs.*依次赋给相同类型的变量
        try {
            float price = 0;
            int snum = 0;
            int bnum = 0;
            PreparedStatement s = con.prepareStatement(
                    “select * from Train where TrainNo = ? “);
            s.setString(1 tb.getTrainNo());
            ResultSet rs = s.executeQuery();
            if (rs.next()) {
                if (rs.getString(“TrainNo“).trim().equals(tb.getTrainNo())) {
                    if (frm.RaidaoHard.isSelected()) {
                        snum = rs.getInt(“SeatNum“);
                        tb.setSeatNum(Integer.parseInt(frm.OrderNum.getText()));
                        if (snum <= 0 ||
                            tb.getSeatNum() > snum) {
                            JOptionPane.showMessageDialog(frm “订购失败:车票数量不足“);
                            return false;
                        }
                        tb.setSeatPrice(rs.getFloat(“seatPrice“));
                        price = tb.getSeatPrice() *
                                tb.getSeatNum();
                   

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5888  2007-07-14 15:27  TrainTicket\bak\trainticket\DB.java~29~

     文件       6030  2007-07-14 15:31  TrainTicket\bak\trainticket\DB.java~30~

     文件       6116  2007-07-14 15:33  TrainTicket\bak\trainticket\DB.java~31~

     文件       6119  2007-07-14 15:34  TrainTicket\bak\trainticket\DB.java~32~

     文件       6115  2007-07-14 15:34  TrainTicket\bak\trainticket\DB.java~33~

     文件       6114  2007-07-14 15:35  TrainTicket\bak\trainticket\DB.java~34~

     文件       6115  2007-07-14 15:36  TrainTicket\bak\trainticket\DB.java~35~

     文件       6118  2007-07-14 15:38  TrainTicket\bak\trainticket\DB.java~36~

     文件       6118  2007-07-14 15:41  TrainTicket\bak\trainticket\DB.java~37~

     文件       4684  2007-07-14 15:56  TrainTicket\bak\trainticket\DB.java~38~

     文件       6125  2007-07-14 15:45  TrainTicket\bak\trainticket\DB.java~39~

     文件       5482  2007-07-13 13:12  TrainTicket\bak\trainticket\frame1.java~18~

     文件       5542  2007-07-13 13:13  TrainTicket\bak\trainticket\frame1.java~19~

     文件       5603  2007-07-14 00:11  TrainTicket\bak\trainticket\frame1.java~20~

     文件       5607  2007-07-14 00:15  TrainTicket\bak\trainticket\frame1.java~21~

     文件       5614  2007-07-14 00:17  TrainTicket\bak\trainticket\frame1.java~22~

     文件       5664  2007-07-14 00:18  TrainTicket\bak\trainticket\frame1.java~23~

     文件       5712  2007-07-14 00:19  TrainTicket\bak\trainticket\frame1.java~24~

     文件       5693  2007-07-14 00:23  TrainTicket\bak\trainticket\frame1.java~25~

     文件       5691  2007-07-14 00:23  TrainTicket\bak\trainticket\frame1.java~26~

     文件       4125  2007-07-14 14:53  TrainTicket\bak\trainticket\frame1.java~27~

     文件       9240  2007-07-14 16:06  TrainTicket\classes\package cache\trainticket.dep2

     文件       4467  2007-07-14 16:05  TrainTicket\classes\trainticket\DB.class

     文件        824  2007-07-14 16:06  TrainTicket\classes\trainticket\frame1$frame1_MainTure_actionAdapter.class

     文件       3992  2007-07-14 16:06  TrainTicket\classes\trainticket\frame1.class

     文件        731  2007-07-11 22:30  TrainTicket\classes\trainticket\Mainframe$1.class

     文件       1213  2007-07-11 22:30  TrainTicket\classes\trainticket\Mainframe.class

     文件       1346  2007-07-11 22:30  TrainTicket\classes\trainticket\TicketBean.class

     文件        588  2007-07-11 21:57  TrainTicket\doc\trainticket\TicketBean.html

     文件       5382  2007-07-14 16:05  TrainTicket\src\trainticket\DB.java

............此处省略22个文件信息

评论

共有 条评论