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

📄 planefcity.java

📁 eclipse java/jsp 航空管理系统
💻 JAVA
字号:
/*
 * @(#)PlaneFcity.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 PlaneFcity {
    /** 建立Connection 对象 */
    Connection con = null;

    //建立一个Statement对象
    Statement stmt = null;

    //建立一个处理结果的ResulSet对象
    ResultSet rs = null;

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

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

        AppMode.registerUser();

        /** 建立Connection 对象 */
        //Connection con = null;
        /** 建立Statement 对象 */
        //Statement stmt = null;
        /** 建立ResultSet 对象 */
        //ResultSet rs = null;*/
        /** 要返回的链表对象 */
        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命令,取得country表中的数据 */
            rs = stmt.executeQuery("Select cityname from country");
            /** 循环将查询到的值加入到链表中 */
            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 e1) {
            System.out.println("table5 not found! ");
        }

        AppMode.loginoutUser();
        /** 返回链表 */
        return myList;
    }

    /** getNumber(参数)方法通过传递城市参数得到城市代号 */
    public String getNumber(List fcity) {

        AppMode.registerUser();

        /** fcityno用来返回要得到的城市代号 */
        String fcityno = "";
        /** temp是一个临时的变量用来得到参数链表中的城市名 */
        String temp = "";
        try {
            /** 连接数据库 */
            db = new DbConnection();
            con = db.getCon();
            ;

            /** 建立Statement对象,以执行SQL命令 */
            stmt = con.createStatement();
            /** 建立一个参数链表的游标 */
            Iterator elements = fcity.iterator();
            /** 当游标没有到达结尾时 */
            while (elements.hasNext()) {
                /** 得到链表中的城市的名字并将它传递给中间变量temp */
                temp = (String) elements.next();
                /** 执行SQL命令,取得country表中的数据 */
                rs = stmt
                        .executeQuery("select no from country where cityname='"
                                + temp + "'");
                /** 循环取得结果集 */
                while (rs.next()) {
                    fcityno = fcityno + String.valueOf(rs.getInt(1));
                    fcityno = fcityno + "|";
                }
            }
            /** 以下的if语句用来关闭数据库连接 */
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
                stmt.close();
                stmt = null;
            }
            if (con != null) {
                con.close();
                con = null;
            }

        } catch (SQLException e1) {
            System.out.println(e1.getMessage());
        }

        AppMode.loginoutUser();

        /** 返回得到的城市代号 */
        return fcityno;
    }

    /** 方法是用来判断城市名是否是数据字典中的城市名 */
    public boolean isFcity(String fcity) {

        AppMode.registerUser();

        /** flag是用来代表的返回类型 */
        boolean flag = true;
        /** 字符串str是用来当作临时变量 */
        String str = "test";
        // 用来捕获数据库操作时的异常
        try {
            /** 连接数据库 */
            db = new DbConnection();
            con = db.getCon();
            /** 建立Statement对象,以执行SQL命令 */
            stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_UPDATABLE);
            /** 执行SQL命令,取得表中的数据 */
            rs = stmt.executeQuery("Select cityname from country where "
                    + "cityname='" + fcity + "'");
            /** 判断是否为空 */
            if (rs != null) {
                //循环用来表示当数据库还有别的数据时
                while (rs.next()) {
                    //加入到链表中去
                    str = rs.getString(1);
                }
                /** 判断是否为fno对应的航空公司 */
                if (fcity.equals(str))
                    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 e1) {
            System.out.println("table not found!");
        }

        AppMode.loginoutUser();

        return flag;
    }
}

⌨️ 快捷键说明

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