⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 planefcom.java

📁 eclipse java/jsp 航空管理系统
💻 JAVA
字号:
/*
 * @(#)PlaneFcom.java
 * 
 * 创建日期 2005-4-21
 * Copyright 2005 东软 国际合作事业部. All rights reserved.
 */
package liyong.model;

import java.util.*;
import java.sql.*;

import zhangchunliang.model.AppMode;

import liyong.ConnectionPool.*;

/**
 * 这个类用来得到航班所属的航空公司,它包含三个 
 * 方法分别用来得到是下拉框要显示的航空公司名 
 * 一个是根据航班号得到航空公司的名字
 * 一个是判断要修改的是否是正确的航空公司
 * 
 * @author 李勇
 * @see Collection
 * @see Set
 * @see ArrayList
 * @see LinkedList
 * @see Vector
 * @see Arrays#asList(Object[])
 * @see Collections#nCopies(int, Object)
 * @see Collections#EMPTY_LIST
 * @see AbstractList
 * @see AbstractSequentialList
 * @see Connection
 * @since 1.2
 */
public class PlaneFcom {
    /** 建立Connection 对象 */
    Connection con = null;

    /** 建立Statement 对象 */
    Statement stmt = null;

    /** 建立ResultSet 对象 */
    ResultSet rs = null;

    /** 建立数据池对象 */
    DbConnection db = null;

    /** 构造函数进行类的初始化建立数据池连接 */
    /** getSelect()方法用来显示航空公司下拉框的值 */
    public List getSelect() {

        AppMode.registerUser();

        /** 要返回的链表对象 */
        List myList = new ArrayList();
        /** 在这里开始捕捉异常 */
        try {
            /** 连接数据库 */
            db = new DbConnection();
            con = db.getCon();
            /** 建立Statement对象,以执行SQL命令 */
            stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_UPDATABLE);
            /** 在链表中加入第一项 */
            myList.add("请选择");
            /** 执行SQL命令,取得表中的数据 */
            rs = stmt.executeQuery("SELECT DISTINCT fcom from flight");
            /** 循环用来得到结果集中的值并把它加入到链表中 */
            while (rs.next()) {
                myList.add(rs.getString(1));
            }
            /** 以下的if语句用来关闭数据库连接 */
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
                stmt.close();
                stmt = null;
            }
            if (con != null) {
                con.close();
                con = null;
            }

        } catch (SQLException e) {
            System.out.println("table3 not found! ");
        }

        AppMode.loginoutUser();

        /** 返回值 */
        return myList;
    }

    /** getFcom()方法通过传递参数fno来查询航空号为fno的航空公司 */
    public String getFcom(String fno) {

        AppMode.registerUser();

        /** 建立一个用来返回的字符串 */
        String str = "";
        /** 开始从这里捕捉异常 */
        try {
            /** 建立数据池对象 */
            db = new DbConnection();
            con = db.getCon();
            /** 建立Statement对象,以执行SQL命令 */
            stmt = con.createStatement();
            /** 执行SQL命令,取得表中的数据 */
            rs = stmt.executeQuery("select fcom from flightcom where fno='"
                    + fno + "'");
            /** 循环用来得到要查询的值 */
            while (rs.next()) {
                str = rs.getString(1);
            }
            /** 以下的if语句用来关闭数据库连接 */
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
                stmt.close();
                stmt = null;
            }
            if (con != null) {
                con.close();
                con = null;
            }

        } catch (SQLException e) {
            System.out.println("table not found");
        }

        AppMode.loginoutUser();

        return str;
    }

    /** 方法是用来判断航班号是否与航空公司相对应 */
    public boolean isFcom(String fno, String fcom) {

        AppMode.registerUser();

        /** 字符串str是用来当作临时变量 */
        String str = "";
        /** flag是用来代表的返回类型 */
        boolean flag = true;
        // 用来捕获数据库操作时的异常
        try {
            /** 建立数据池对象 */
            db = new DbConnection();
            con = db.getCon();
            /** 建立Statement对象,以执行SQL命令 */
            stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_UPDATABLE);
            /** 执行SQL命令,取得表中的数据 */
            rs = stmt.executeQuery("Select fcom from flightcom where fno='"
                    + fno + "'");
            if (rs != null) {
                //循环用来表示当数据库还有别的数据时
                while (rs.next()) {
                    //加入到链表中去
                    str = rs.getString(1);
                }
                /** 判断是否为fno对应的航空公司 */
                if (str.equals(fcom))
                    flag = true;
                else
                    flag = false;
            } else
                flag = false;
            //以下的if语句用来结束数据库操作
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
                stmt.close();
                stmt = null;
            }
            if (con != null) {
                con.close();
                con = null;
            }

        } catch (SQLException e) {
            System.out.println("table not found!");
        }

        AppMode.loginoutUser();

        return flag;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -