我想显示以下信息 -
日期航班 | 姓名 出发时间 | 商务舱可用性 | 行政舱可用性 | 经济舱可用性
现在所有信息都在不同的表中
Table sector - sectorID | description | weekday1 | weekday2 | bfare | xfare | efare
Table flights - flightno | deptime | arrtime | aircrafttypeID | sectorID
Table aircraft - aircraftTypeID | description | bseats | xseats | eseats
scheduleID - flightno | flightdate | bcsavailable | xcsavailable | ecsavailable
查询:显示计划于 2013 年 6 月 17 日从加尔各答到艾哈迈达巴德的航班,舱位是商务舱。
第 1 部分 - 我正在尝试获取座位数大于 0 且来源和目的地匹配的航班号,第 2 部分 - 然后我将从 scheduleflights 表中获取日期和航班号匹配的那些记录。当我在 MySQL 查询窗口中运行此查询时,我得到了正确的输出,但是当我在 Java 中执行相同的查询时,它给了我一个错误 -
列索引超出范围,2 > 1。
SQL 版本
SELECT flightno
FROM flights
WHERE aircrafttypeID
IN (
SELECT aircraftTypeID
FROM aircraft
WHERE aircrafttypeID
IN (
SELECT aircrafttypeID
FROM sector, flights
WHERE source LIKE 'Kolkata'
AND destination LIKE 'Ahmedabad'
AND sector.sectorID = flights.sectorID
)
AND bseats >0)
上述查询的输出是正确的 FJA23 和 FJA24 2 条记录。
Java版
String origin=jComboBox3.getSelectedItem().toString();
String target=jComboBox4.getSelectedItem().toString();
String fclass=jComboBox1.getSelectedItem().toString();
String search = "";
if(fclass.equals("Business"))
{
search="AND bseats>0";
}
if(fclass.equals("Executive"))
{
search="AND xseats>0";
}
if(fclass.equals("Economy"))
{
search="AND eseats>0";
}
String sql="SELECT flightno FROM flights WHERE aircrafttypeID IN "
+ "(SELECT aircraft.aircrafttypeID FROM aircraft WHERE aircrafttypeID IN "
+ "(SELECT aircrafttypeID FROM sector,flights WHERE source LIKE '"+ origin
+ "' AND destination LIKE '" + target + "' AND sector.sectorID=flights.sectorID) " + search+")";
System.out.println(sql);