组队-地铁查询
组队队友周正阳一起学习了线路的查询
完成了线路查询的相关函数和jsp
package com.Dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.DBUtil.SubwayDBUtil;
public class DataBuilder {
public static List<Station> line1 = new ArrayList<Station>();//1号线
public static List<Station> line2 = new ArrayList<Station>();//2号线
// public static List<Station> line3 = new ArrayList<Station>();//3号线
// public static List<Station> line4 = new ArrayList<Station>();//4号线
// public static List<Station> line5 = new ArrayList<Station>();//5号线
// public static List<Station> line6 = new ArrayList<Station>();//6号线
public static Set<List<Station>> lineSet = new HashSet<List<Station>>();//所有线集合
public static int totalStaion = 0;//总的站点数量
static {
/*******************************************************************************/
//1号线
String[] line1Arr = new String[29];
Connection conn1 = SubwayDBUtil.getConn();
try {
Statement stmt = conn1.createStatement();
String sql = "select * from line where lineid=1";
ResultSet rs = stmt.executeQuery(sql);
int k = 0;
while(rs.next()) {
line1Arr[k] = rs.getString("stationname");
k++;
}
conn1.close();
} catch (SQLException e) {
e.printStackTrace();
}
for(String s : line1Arr) {
line1.add(new Station(s));
}
for(int i =0;i<line1.size();i++) {
if(i<line1.size()-1) {
line1.get(i).next = line1.get(i+1);
line1.get(i+1).prev = line1.get(i);
}
}
/*******************************************************************************/
//2号线
String[] line2Arr = new String[37];
Connection conn2 = SubwayDBUtil.getConn();
try {
Statement stmt = conn2.createStatement();
String sql = "select * from line where lineid=2";
ResultSet rs = stmt.executeQuery(sql);
int k = 0;
while(rs.next()) {
line2Arr[k] = rs.getString("stationname");
k++;
}
conn2.close();
} catch (SQLException e) {
e.printStackTrace();
}
for(String s : line2Arr) {
line2.add(new Station(s));
}
for(int i =0;i<line2.size();i++) {
if(i<line2.size()-1) {
line2.get(i).next = line2.get(i+1);
line2.get(i+1).prev = line2.get(i);
}
}
/*******************************************************************************/
//3号线
// String[] line3Arr = new String[35];
// Connection conn3 = SubwayDBUtil.getConn();
// try {
// Statement stmt = conn3.createStatement();
// String sql = "select * from line where lineid=3";
// ResultSet rs = stmt.executeQuery(sql);
// int k = 0;
// while(rs.next()) {
// line3Arr[k] = rs.getString("stationname");
// k++;
// }
// conn3.close();
// } catch (SQLException e) {
// e.printStackTrace();
// }
//
// for(String s : line3Arr) {
// line3.add(new Station(s));
// }
// for(int i =0;i<line3.size();i++) {
// if(i<line3.size()-1) {
// line3.get(i).next = line3.get(i+1);
// line3.get(i+1).prev = line3.get(i);
// }
// }
/*******************************************************************************/
// //4号线
// String[] line4Arr = new String[18];
// Connection conn4 = SubwayDBUtil.getConn();
// try {
// Statement stmt = conn4.createStatement();
// String sql = "select * from line where lineid=4";
// ResultSet rs = stmt.executeQuery(sql);
// int k = 0;
// while(rs.next()) {
// line4Arr[k] = rs.getString("stationname");
// k++;
// }
// conn4.close();
// } catch (SQLException e) {
// e.printStackTrace();
// }
//
// for(String s : line4Arr) {
// line4.add(new Station(s));
// }
// for(int i =0;i<line4.size();i++) {
// if(i<line4.size()-1) {
// line4.get(i).next = line4.get(i+1);
// line4.get(i+1).prev = line4.get(i);
// }
// }
/*******************************************************************************/
//5号线
// String[] line5Arr = new String[21];
// Connection conn5 = SubwayDBUtil.getConn();
// try {
// Statement stmt = conn5.createStatement();
// String sql = "select * from line where lineid=5";
// ResultSet rs = stmt.executeQuery(sql);
// int k = 0;
// while(rs.next()) {
// line5Arr[k] = rs.getString("stationname");
// k++;
// }
// conn5.close();
// } catch (SQLException e) {
// e.printStackTrace();
// }
//
// for(String s : line5Arr) {
// line5.add(new Station(s));
// }
// for(int i =0;i<line5.size();i++) {
// if(i<line5.size()-1) {
// line5.get(i).next = line5.get(i+1);
// line5.get(i+1).prev = line5.get(i);
// }
// }
/*******************************************************************************/
//s8号线
// String[] line6Arr = new String[19];
// Connection conn6 = SubwayDBUtil.getConn();
// try {
// Statement stmt = conn6.createStatement();
// String sql = "select * from line where lineid=6";
// ResultSet rs = stmt.executeQuery(sql);
// int k = 0;
// while(rs.next()) {
// line6Arr[k] = rs.getString("stationname");
// k++;
// }
// conn6.close();
// } catch (SQLException e) {
// e.printStackTrace();
// }
//
// for(String s : line6Arr) {
// line6.add(new Station(s));
// }
// for(int i =0;i<line6.size();i++) {
// if(i<line6.size()-1) {
// line6.get(i).next = line6.get(i+1);
// line6.get(i+1).prev = line6.get(i);
// }
// }
/*******************************************************************************/
lineSet.add(line1);
lineSet.add(line2);
// lineSet.add(line3);
// lineSet.add(line4);
// lineSet.add(line5);
// lineSet.add(line6);
totalStaion = line1.size() + line2.size() ;
//totalStaion = line1.size() + line2.size() + line3.size() + line4.size() + line5.size() + line6.size();
System.out.println("总的站点数量:"+totalStaion);
}
public static void main(String[] args) {
System.out.println("总的站点数量:"+totalStaion);
}
}