📄 planefcountry.java
字号:
/*
* @(#)PlaneFcountry.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.*;
/**
* 这个类用来返回一个List类型的链表,代表要查询的航班国籍
*
* @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 PlaneFcountry {
// 建立Connection对象
Connection con = null;
//建立Satement对象
Statement stmt = null;
//建立ResultSet对象
ResultSet rs = null;
/** 建立数据池对象 */
DbConnection db = null;
/** 构造函数进行类的初始化建立数据池连接 */
//用来得到下拉框中的航班国际,其中两个参数前一个代表数据库中的国家名,后一个为表名
public List getSelect(String country, String fplane) {
AppMode.registerUser();
/** 构造函数进行类的初始化建立数据池连接 */
//建立返回的List对象
List myList = new ArrayList();
//捕捉数据库操作的异常
try {
db = new DbConnection();
con = db.getCon();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
//下拉框中添加第一项
myList.add("请选择");
rs = stmt.executeQuery("SELECT DISTINCT " + country + " from "
+ fplane);
//循环得到所有的结果集
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("table not found! ");
}
AppMode.loginoutUser();
//返回值
return myList;
}
/** 方法是用来判断航空国籍是否是数据字典中的航空国籍 */
public boolean isFcountry(String fcountry) {
AppMode.registerUser();
/** flag是用来代表的返回类型 */
boolean flag = true;
/** 字符串str是用来当作临时变量用来得到返回的fcountry */
String str = "test";
// 用来捕获数据库操作时的异常
try {
db = new DbConnection();
con = db.getCon();
/** 加载JDBC驱动 */
/** 建立Statement对象,以执行SQL命令 */
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
/** 执行SQL命令,取得表中的数据 */
rs = stmt.executeQuery("Select countryname from country where "
+ "countryname='" + fcountry + "'");
/** 判断是否为空 */
if (rs != null) {
//循环用来表示当数据库还有别的数据时
while (rs.next()) {
//加入到链表中去
str = rs.getString(1);
}
/** 判断是否为fno对应的航空公司 */
if (fcountry.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 e) {
System.out.println("table not found!");
}
AppMode.loginoutUser();
return flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -