• 石家庄地铁查询双人项目进度总结


    结组人:赵路仓 李嘉兴

    首先是结果:

    首先思路是用最笨的穷举法,首先定义一个finally_start(最终的起点),finally_end,(最终的终点)mid1(最终的中转站1),mid2(最终的中转站2),mid3(最终的中转站3),mid4(最终的中转站4),main_start(最终的起点线路),main_end(最终的终点线路)

    然后判断起点终点是否在一条线路上,若在直接输出这几个值。

    若不在则,举出转一站,转两站的全部情况,并将中转站和起点终点站号以及线路存在几个数组中,利用count【】存储每个情况的总站数,比较总站数,输出总站数最小的一组数值

     然后用list函数利用该函数输出到web页面中。

    我负责后台,李嘉兴负责前端,在两天的学习中我完成了基础功能,但发现存在漏洞,然后利用一天的时间完善。

    后台源代码:

       1 package alone;
       2 
       3 import java.sql.*;
       4 import java.util.ArrayList;
       5 import java.util.List;
       6 import java.util.Scanner;
       7 
       8 import alone.User;
       9 
      10 import alone.Daotest;
      11 import alone.Util;
      12 
      13 public class LoginerDaoImpl  {
      14 
      15     static Connection conn;
      16     static PreparedStatement ps = null;
      17     static ResultSet rs;
      18     static String sql = "select * from Metro";   //连接数据库
      19     static Util ut= new Util();
      20     static Scanner in = new Scanner(System.in);
      21     static int station_number;            //站号
      22     static String station_name;        //站名
      23     static int station_change;            //是否有无中转站号
      24     static int station_main;            //线路号
      25     static int station_start;             //起点站号
      26     static int station_change_one;        //第一条线终点中转站站号    
      27     static int station_change_two;        //另二条线起点中转站站号
      28     static int station_change_three;        //第二条线终点中转站站号
      29     static int station_change_four;       //第三条线起点中转站站号
      30     static int station_end;                //终点站站号
      31     static int main_start;                //起点线路
      32     static int main_end;                //终点线路
      33     static int alone_sum;                //单条线路总站数
      34     static int change_copy;
      35     static int station_change_one_main;    
      36     static int station_change_two_main;    
      37     static int station_change_three_main;
      38     static int station_change_four_main;
      39     static int sum;
      40     
      41     static int[] count=new int[40];
      42     static int[] main_start_=new int[40];
      43     static int[] main_end_=new int[40];
      44     static int[] mid1=new int[40];
      45     static int[] mid2=new int[40];
      46     static int[] mid3=new int[40];
      47     static int[] mid4=new int[40];
      48     static int[] finally_start_=new int[40];
      49     static int[] finally_end_=new int[40];
      50     static int finally_start;
      51     static int finally_end;
      52     static int finally_mid1;
      53     static int finally_mid2;
      54     static int finally_mid3=0;
      55     static int finally_mid4=0;
      56     static int thought_a=0;
      57     static int thought_b=0;
      58     static int judge_one=0;
      59     public static int station_number() 
      60     {
      61         return station_number;
      62     }
      63     public static int station_main() 
      64     {
      65         return station_main;
      66     }
      67     public static String station_name()
      68     {
      69         return station_name;
      70     }
      71     public static int station_change() 
      72     {
      73         return station_change;
      74     }
      75 
      76     public static List<User> loada(String a) throws SQLException
      77     {
      78 //        sql="select * from station where station_name= ?";   //起点站号
      79 //        ps=conn.prepareStatement(sql);
      80 //        ps.setString(1, a);
      81 //        ResultSet aa=ps.executeQuery();
      82 //        if(aa.next()) 
      83 //        {
      84 //            main_start=aa.getInt("station_main");
      85 //            station_start=aa.getInt(1);
      86 //            System.out.println(station_start);
      87 //            finally_start=station_start;
      88 //        }
      89         
      90         Connection connection = Util.getConn();
      91         sql="select * from station where station_name= ? and station_alone=?";
      92         PreparedStatement preparedStatement = null;
      93         ResultSet resultSet = null;
      94         List<User> users = new ArrayList<User>();
      95         User user = null;
      96         try {
      97             preparedStatement = connection.prepareStatement(sql);
      98             preparedStatement.setString(1, a);
      99             preparedStatement.setInt(2, 1);
     100             resultSet = preparedStatement.executeQuery();
     101             while(resultSet.next()) {
     102                 user = new User();
     103                 main_start=resultSet.getInt("station_main");
     104                 station_start=resultSet.getInt(1);
     105                 System.out.println(station_start);
     106                 finally_start=station_start;
     107                 users.add(user);
     108             }
     109         } catch (SQLException h) {
     110             // TODO Auto-generated catch block
     111             h.printStackTrace();
     112         }finally {
     113             Util.close(resultSet);
     114             Util.close(preparedStatement);
     115             Util.close(connection);
     116         }
     117         return  users;
     118     } 
     119 
     120 
     121     @SuppressWarnings("resource")
     122     public static void hightestfind(String b ,String d) throws SQLException 
     123     {
     124     
     125     
     126     
     127     
     128 //        int a=Integer.parseInt(e);
     129 //        main_start=a;
     130 //        int c=Integer.parseInt(f);
     131 //        main_end=c;
     132         thought_a=0;
     133         thought_b=0;
     134         int a=0;
     135         int c=0;
     136         int k=0;
     137         int l=0;
     138         try 
     139         {
     140             for(int u=0;u<3;u++)
     141             {
     142                 for(int o=0;o<40;o++)
     143                 {
     144                     mid3[o]=0;
     145                 }
     146                 if(u==0)
     147                 {
     148                     k=0;
     149                     l=1;
     150                 }
     151                 if(u==1)
     152                 {
     153                     k=1;
     154                     l=1;
     155                 }
     156                 if(u==2)
     157                 {
     158                     k=1;
     159                     l=0;
     160                 }
     161                 if(u==3)
     162                 {
     163                     k=0;
     164                     l=0;
     165                 }
     166 
     167                 alone_sum=0;                //单条线路总站数
     168                 change_copy=0;
     169                 sum=0;
     170                 finally_start=0;
     171                 finally_end=0;
     172                 finally_mid1=0;
     173                 finally_mid2=0;
     174                 finally_mid3=0;
     175                 finally_mid4=0;
     176             
     177         conn=ut.getConn();
     178         ps=null;
     179         ResultSet rs=null;
     180         sql="select * from station where station_name=?  and station_alone=?";   //起点站号
     181         ps=conn.prepareStatement(sql);
     182         ps.setString(1, b);
     183         ps.setInt(2, k);
     184         ResultSet aa=ps.executeQuery();
     185         if(aa.next()) 
     186         {
     187             
     188             main_start=aa.getInt("station_main");
     189             a=main_start;
     190             station_start=aa.getInt(1);
     191             System.out.println(station_start);
     192             
     193         }
     194         
     195         sql="select * from station where station_name=?  and station_alone=?";    //终点站号
     196         ps=conn.prepareStatement(sql);
     197         ps.setString(1,d);
     198         ps.setInt(2,l);
     199         ResultSet ff=ps.executeQuery();
     200         if(ff.next()) 
     201         {
     202             
     203             main_end=ff.getInt("station_main");
     204             c=main_end;
     205             station_end=ff.getInt(1);
     206             System.out.println(station_end);
     207             
     208         }
     209     
     210         if(a==c) 
     211         {    
     212             
     213             
     214             thought_a++;
     215             if(station_start<=station_end)                                     //起点在终点之前
     216             {
     217                 sql="select * from station where station_number>=?";    //起点站号
     218                 ps=conn.prepareStatement(sql);
     219                 ps.setInt(1,station_start);
     220                 rs=ps.executeQuery();
     221                 while(rs.next()&&station_number!=station_end) 
     222                 {
     223                     station_number = rs.getInt("station_number");
     224                     station_name = rs.getString("station_name");
     225                     station_change= rs.getInt("station_change");
     226                     station_main= rs.getInt("station_main");
     227                     System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     228                     alone_sum++;
     229                 }
     230                 
     231             }
     232             if(station_start>=station_end)                                     //起点在终点之后
     233             {
     234                 sql="select * from station where station_number=?";    //起点站号
     235                 ps=conn.prepareStatement(sql);
     236                 for(int i=station_start;i>=station_end;i--) 
     237                 {
     238                     ps.setInt(1, i);
     239                     rs=ps.executeQuery();
     240                     if(rs.next()) 
     241                     {
     242                         station_number = rs.getInt("station_number");
     243                         station_name = rs.getString("station_name");
     244                         station_change= rs.getInt("station_change");
     245                         station_main= rs.getInt("station_main");
     246                         System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     247                         alone_sum++;
     248                     }
     249                 }    
     250             }
     251             System.out.println("*********************************");
     252             System.out.println("一共经过"+alone_sum+"");
     253             System.out.println("*********************************");
     254             System.out.println(finally_start+"  "+finally_end);
     255              finally_start=station_start;
     256              finally_end=station_end;
     257              main_start_[thought_a]=main_start;
     258                 main_end_[thought_a]=main_end;
     259                 finally_start_[thought_a]=finally_start;
     260                 finally_end_[thought_a]=finally_end;
     261                 count[thought_a]=alone_sum;
     262             
     263         }
     264         
     265         
     266         
     267         if(a!=c)                         //a和c在两条地铁线路
     268         {                              
     269               //自定义整形以判断是否到达中转站
     270 //        sql="select * from station where station_name=? and station_main=?";   //起点站号
     271 //        ps=conn.prepareStatement(sql);
     272 //        ps.setString(1,b);
     273 //        ps.setInt(2,a);
     274 //        ResultSet aa=ps.executeQuery();
     275 //        if(aa.next()) 
     276 //        {    
     277 //            main_start=aa.getInt("station_main");                    //起点线路号
     278 //            station_start=aa.getInt(1);
     279 //            System.out.println("起点"+"  "+main_start+"   "+station_start);
     280 //        }
     281 //        sql="select * from station where station_name=? and station_main=?";   //起点站号
     282 //        ps=conn.prepareStatement(sql);
     283 //        ps.setString(1,d);
     284 //        ps.setInt(2,c);
     285 //        ResultSet ff=ps.executeQuery();
     286 //        if(ff.next()) 
     287 //        {    
     288 //            main_end=ff.getInt("station_main");                    //起点线路号
     289 //            station_end=ff.getInt(1);
     290 //            System.out.println("终点"+"  "+main_end+"   "+station_end);
     291 //        }
     292         
     293         
     294         
     295         
     296             
     297             //转一站
     298             for(int j=1;j<3;j++)
     299             {
     300                 
     301                 sum=0;
     302                 change_copy=j;
     303                 sql="select * from station where station_change=? and change_copy=?";    //中转站
     304                 ps=conn.prepareStatement(sql);
     305                 ps.setInt(1, 10*a+c);
     306                 ps.setInt(2, change_copy);
     307                 ResultSet bb=ps.executeQuery();
     308                 if(bb.next())
     309                 {
     310                     station_change_one_main=bb.getInt("station_main");
     311                     station_change_one=bb.getInt("station_number");
     312                     System.out.println("中转站"+"  "+station_change_one_main+"  "+station_change_one);
     313                 }
     314                 else
     315                 {
     316                     continue;
     317                 }
     318                 judge_one++;
     319                 thought_a++;
     320                 if(station_start<=station_change_one)
     321                 {
     322                     sql="select * from station where station_number>=?";
     323                     ps=conn.prepareStatement(sql);
     324                     ps.setInt(1, station_start);
     325                     rs=ps.executeQuery();
     326                     while(rs.next()&&station_number!=station_change_one)
     327                     {
     328                             sum++;
     329                             station_number = rs.getInt("station_number");
     330                             station_name = rs.getString("station_name");
     331                             station_change= rs.getInt("station_change");
     332                             station_main= rs.getInt("station_main");
     333                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     334                     }
     335                     
     336                     
     337                 }
     338                 if(station_start>=station_change_one)
     339                 {
     340                     sql="select * from station where station_number=?";    //起点站号
     341                     ps=conn.prepareStatement(sql);
     342                     for(int i1=station_start;i1>=station_change_one;i1--) 
     343                     {
     344                         ps.setInt(1, i1);
     345                         rs=ps.executeQuery();
     346                         if(rs.next()) 
     347                         {
     348                             sum++;
     349                             station_number = rs.getInt("station_number");
     350                             station_name = rs.getString("station_name");
     351                             station_change= rs.getInt("station_change");
     352                             station_main= rs.getInt("station_main");
     353                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     354                         }
     355                     }
     356                 }
     357                 
     358                 sql="select * from station where station_change=? and change_copy=?";    //中转站2站号
     359                 ps=conn.prepareStatement(sql);
     360                 ps.setInt(1, 10*c+a);
     361                 ps.setInt(2, change_copy);
     362                 ResultSet cc=ps.executeQuery();
     363                 if(cc.next()) 
     364                 {
     365                     station_change_two_main=cc.getInt("station_main");
     366                     station_change_two=cc.getInt(1);
     367                     System.out.println("中转站2"+"  "+station_change_two_main+"  "+station_change_two);
     368                 }
     369                 
     370                 if(main_end==station_change_two_main)
     371                 {
     372                     if(station_change_two<=station_end)
     373                     {
     374                         sql="select * from station where station_number>=?";
     375                         ps=conn.prepareStatement(sql);
     376                         ps.setInt(1, station_change_two);
     377                         rs=ps.executeQuery();
     378                         while(rs.next()&&station_number!=station_end)
     379                         {
     380                                 sum++;
     381                                 station_number = rs.getInt("station_number");
     382                                 station_name = rs.getString("station_name");
     383                                 station_change= rs.getInt("station_change");
     384                                 station_main= rs.getInt("station_main");
     385                                 System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     386                            
     387                         }
     388                     }
     389                     if(station_change_two>=station_end)
     390                     {
     391                         sql="select * from station where station_number=?";    //起点站号
     392                         ps=conn.prepareStatement(sql);
     393                         for(int i1=station_change_two;i1>=station_end;i1--) 
     394                         {
     395                             ps.setInt(1, i1);
     396                             rs=ps.executeQuery();
     397                             if(rs.next()) 
     398                             {
     399                                 sum++;
     400                                 station_number = rs.getInt("station_number");
     401                                 station_name = rs.getString("station_name");
     402                                 station_change= rs.getInt("station_change");
     403                                 station_main= rs.getInt("station_main");
     404                                 System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     405                             }
     406                         }
     407                     }
     408                      finally_start=station_start;
     409                      finally_end=station_end;
     410                      main_start_[thought_a]=main_start;
     411                         main_end_[thought_a]=main_end;
     412                         finally_start_[thought_a]=finally_start;
     413                         finally_end_[thought_a]=finally_end;
     414                      mid1[thought_a]=station_change_one;
     415                      mid2[thought_a]=station_change_two;
     416                      count[thought_a]=sum-1;
     417                     System.out.println(""+(sum-1));
     418                 }
     419             }
     420             
     421             
     422             
     423             //转两站1-1
     424             for(int i=1;i<7;i++)
     425             {
     426                 if(i==main_end||i==main_start)
     427                 {
     428                     continue;
     429                 }
     430                 thought_a++;
     431                 sum=0;
     432                 System.out.println("-------------------------------------------------------------");
     433                 System.out.println("到站点"+i);
     434                 change_copy=1;
     435                 sql="select * from station where station_change=? and change_copy=?";    //中转站
     436                 ps=conn.prepareStatement(sql);
     437                 ps.setInt(1, 10*a+i);
     438                 ps.setInt(2, change_copy);
     439                 ResultSet bb=ps.executeQuery();
     440                 if(bb.next())
     441                 {
     442                     station_change_one_main=bb.getInt("station_main");
     443                     station_change_one=bb.getInt("station_number");
     444                     System.out.println("中转站"+"  "+station_change_one_main+"  "+station_change_one);
     445                 }
     446                 if(station_start<=station_change_one)
     447                 {
     448                     sql="select * from station where station_number>=?";
     449                     ps=conn.prepareStatement(sql);
     450                     ps.setInt(1, station_start);
     451                     rs=ps.executeQuery();
     452                     while(rs.next()&&station_number!=station_change_one)
     453                     {        
     454                             sum++;
     455                             station_number = rs.getInt("station_number");
     456                             station_name = rs.getString("station_name");
     457                             station_change= rs.getInt("station_change");
     458                             station_main= rs.getInt("station_main");
     459                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     460                     }
     461                 }
     462                 if(station_start>=station_change_one)
     463                 {
     464                     sql="select * from station where station_number=?";    //起点站号
     465                     ps=conn.prepareStatement(sql);
     466                     for(int i1=station_start;i1>=station_change_one;i1--) 
     467                     {
     468                         ps.setInt(1, i1);
     469                         rs=ps.executeQuery();
     470                         if(rs.next()) 
     471                         {
     472                             sum++;
     473                             station_number = rs.getInt("station_number");
     474                             station_name = rs.getString("station_name");
     475                             station_change= rs.getInt("station_change");
     476                             station_main= rs.getInt("station_main");
     477                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     478                         }
     479                     }
     480                 }
     481                 sql="select * from station where station_change=? and change_copy=?";    //中转站2站号
     482                 ps=conn.prepareStatement(sql);
     483                 ps.setInt(1, 10*i+a);
     484                 ps.setInt(2, 1);
     485                 ResultSet cc=ps.executeQuery();
     486                 if(cc.next()) 
     487                 {
     488                     station_change_two_main=cc.getInt("station_main");
     489                     station_change_two=cc.getInt(1);
     490                     System.out.println("中转站2"+"  "+station_change_two_main+"  "+station_change_two);
     491                 }
     492                 
     493                 sql="select * from station where station_change=? and change_copy=?";    //中转站3站号
     494                 ps=conn.prepareStatement(sql);
     495                 ps.setInt(1, 10*station_change_two_main+c);
     496                 ps.setInt(2, 1);
     497                 ResultSet dd=ps.executeQuery();
     498                 if(dd.next()) 
     499                 {
     500                     station_change_three_main=dd.getInt("station_main");
     501                     station_change_three=dd.getInt(1);
     502                     System.out.println("中转站3"+"  "+station_change_three_main+"  "+station_change_three);
     503                 }
     504                 if(station_change_two<=station_change_three)
     505                 {
     506                     sql="select * from station where station_number>=?";
     507                     ps=conn.prepareStatement(sql);
     508                     ps.setInt(1,station_change_two);
     509                     rs=ps.executeQuery();
     510                     while(rs.next()&&station_number!=station_change_three)
     511                     {
     512                             sum++;
     513                             station_number = rs.getInt("station_number");
     514                             station_name = rs.getString("station_name");
     515                             station_change= rs.getInt("station_change");
     516                             station_main= rs.getInt("station_main");
     517                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     518                        
     519                     }
     520                 }
     521                 if(station_change_two>=station_change_three)
     522                 {
     523                     sql="select * from station where station_number=?";    
     524                     ps=conn.prepareStatement(sql);
     525                     for(int i1=station_change_two;i1>=station_change_three;i1--) 
     526                     {
     527                         ps.setInt(1, i1);
     528                         rs=ps.executeQuery();
     529                         if(rs.next()) 
     530                         {
     531                             sum++;
     532                             station_number = rs.getInt("station_number");
     533                             station_name = rs.getString("station_name");
     534                             station_change= rs.getInt("station_change");
     535                             station_main= rs.getInt("station_main");
     536                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     537                         }
     538                     }
     539                 }
     540                 sql="select * from station where station_change=? and change_copy=?";    //中转站4站号
     541                 ps=conn.prepareStatement(sql);
     542                 ps.setInt(1, 10*c+station_change_three_main);
     543                 ps.setInt(2, 1);
     544                 ResultSet ee=ps.executeQuery();
     545                 if(ee.next()) 
     546                 {
     547                     station_change_four_main=ee.getInt("station_main");
     548                     station_change_four=ee.getInt(1);
     549                     System.out.println("中转站4"+"  "+station_change_four_main+"  "+station_change_four);
     550                 }
     551                 
     552                 
     553                 if(station_change_four<=station_end)
     554                 {
     555                     
     556                     sql="select * from station where station_number>=?";
     557                     ps=conn.prepareStatement(sql);
     558                     ps.setInt(1, station_change_four);
     559                     rs=ps.executeQuery();
     560                     while(rs.next()&&station_number!=station_end)
     561                     {
     562                             sum++;
     563                             station_number = rs.getInt("station_number");
     564                             station_name = rs.getString("station_name");
     565                             station_change= rs.getInt("station_change");
     566                             station_main= rs.getInt("station_main");
     567                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     568                        
     569                     }
     570                 }
     571                 
     572                 if(station_change_four>=station_end)
     573                 {
     574                     sql="select * from station where station_number=?";    //起点站号
     575                     ps=conn.prepareStatement(sql);
     576                     for(int i1=station_change_four;i1>=station_end;i1--) 
     577                     {
     578                         ps.setInt(1, i1);
     579                         rs=ps.executeQuery();
     580                         if(rs.next()) 
     581                         {
     582                             sum++;
     583                             station_number = rs.getInt("station_number");
     584                             station_name = rs.getString("station_name");
     585                             station_change= rs.getInt("station_change");
     586                             station_main= rs.getInt("station_main");
     587                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     588                             
     589                         }
     590                     }
     591                 }
     592                 finally_start=station_start;
     593                  finally_end=station_end;
     594                  main_start_[thought_a]=main_start;
     595                     main_end_[thought_a]=main_end;
     596                     finally_start_[thought_a]=finally_start;
     597                     finally_end_[thought_a]=finally_end;
     598                  mid1[thought_a]=station_change_one;
     599                  mid2[thought_a]=station_change_two;
     600                  mid3[thought_a]=station_change_three;
     601                  mid4[thought_a]=station_change_four;
     602                  count[thought_a]=sum-2;
     603                 System.out.println(""+(sum-2));
     604             }
     605             
     606             
     607             
     608             //转两站2-1
     609             for(int i=1;i<7;i++)
     610             {
     611                 if(i==main_end||i==main_start)
     612                 {
     613                     continue;
     614                 }
     615                 sum=0;
     616                 change_copy=2;
     617                 sql="select * from station where station_change=? and change_copy=?";    //中转站
     618                 ps=conn.prepareStatement(sql);
     619                 ps.setInt(1, 10*a+i);
     620                 ps.setInt(2, change_copy);
     621                 ResultSet bb=ps.executeQuery();
     622                 if(bb.next())
     623                 {
     624                     station_change_one_main=bb.getInt("station_main");
     625                     station_change_one=bb.getInt("station_number");
     626                     
     627                 }
     628                 else
     629                 {
     630                     continue;
     631                 }
     632                 thought_a++;
     633                 System.out.println("-------------------------------------------------------------");
     634                 System.out.println("到站点"+i);
     635                 System.out.println("中转站"+"  "+station_change_one_main+"  "+station_change_one);
     636                 if(station_start<=station_change_one)
     637                 {
     638                     sql="select * from station where station_number>=?";
     639                     ps=conn.prepareStatement(sql);
     640                     ps.setInt(1, station_start);
     641                     rs=ps.executeQuery();
     642                     while(rs.next()&&station_number!=station_change_one)
     643                     {        
     644                             sum++;
     645                             station_number = rs.getInt("station_number");
     646                             station_name = rs.getString("station_name");
     647                             station_change= rs.getInt("station_change");
     648                             station_main= rs.getInt("station_main");
     649                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     650                     }
     651                 }
     652                 if(station_start>=station_change_one)
     653                 {
     654                     sql="select * from station where station_number=?";    //起点站号
     655                     ps=conn.prepareStatement(sql);
     656                     for(int i1=station_start;i1>=station_change_one;i1--) 
     657                     {
     658                         ps.setInt(1, i1);
     659                         rs=ps.executeQuery();
     660                         if(rs.next()) 
     661                         {
     662                             sum++;
     663                             station_number = rs.getInt("station_number");
     664                             station_name = rs.getString("station_name");
     665                             station_change= rs.getInt("station_change");
     666                             station_main= rs.getInt("station_main");
     667                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     668                         }
     669                     }
     670                 }
     671                 sql="select * from station where station_change=? and change_copy=?";    //中转站2站号
     672                 ps=conn.prepareStatement(sql);
     673                 ps.setInt(1, 10*i+a);
     674                 ps.setInt(2, change_copy);
     675                 ResultSet cc=ps.executeQuery();
     676                 if(cc.next()) 
     677                 {
     678                     station_change_two_main=cc.getInt("station_main");
     679                     station_change_two=cc.getInt(1);
     680                     System.out.println("中转站2"+"  "+station_change_two_main+"  "+station_change_two);
     681                 }
     682                 
     683                 sql="select * from station where station_change=? and change_copy=?";    //中转站3站号
     684                 ps=conn.prepareStatement(sql);
     685                 ps.setInt(1, 10*station_change_two_main+c);
     686                 ps.setInt(2, 1);
     687                 ResultSet dd=ps.executeQuery();
     688                 if(dd.next()) 
     689                 {
     690                     station_change_three_main=dd.getInt("station_main");
     691                     station_change_three=dd.getInt(1);
     692                     System.out.println("中转站3"+"  "+station_change_three_main+"  "+station_change_three);
     693                 }
     694                 if(station_change_two<=station_change_three)
     695                 {
     696                     sql="select * from station where station_number>=?";
     697                     ps=conn.prepareStatement(sql);
     698                     ps.setInt(1,station_change_two);
     699                     rs=ps.executeQuery();
     700                     while(rs.next()&&station_number!=station_change_three)
     701                     {
     702                             sum++;
     703                             station_number = rs.getInt("station_number");
     704                             station_name = rs.getString("station_name");
     705                             station_change= rs.getInt("station_change");
     706                             station_main= rs.getInt("station_main");
     707                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     708                        
     709                     }
     710                 }
     711                 if(station_change_two>=station_change_three)
     712                 {
     713                     sql="select * from station where station_number=?";    
     714                     ps=conn.prepareStatement(sql);
     715                     for(int i1=station_change_two;i1>=station_change_three;i1--) 
     716                     {
     717                         ps.setInt(1, i1);
     718                         rs=ps.executeQuery();
     719                         if(rs.next()) 
     720                         {
     721                             sum++;
     722                             station_number = rs.getInt("station_number");
     723                             station_name = rs.getString("station_name");
     724                             station_change= rs.getInt("station_change");
     725                             station_main= rs.getInt("station_main");
     726                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     727                         }
     728                     }
     729                 }
     730                 sql="select * from station where station_change=? and change_copy=?";    //中转站4站号
     731                 ps=conn.prepareStatement(sql);
     732                 ps.setInt(1, 10*c+station_change_three_main);
     733                 ps.setInt(2, 1);
     734                 ResultSet ee=ps.executeQuery();
     735                 if(ee.next()) 
     736                 {
     737                     station_change_four_main=ee.getInt("station_main");
     738                     station_change_four=ee.getInt(1);
     739                     System.out.println("中转站4"+"  "+station_change_four_main+"  "+station_change_four);
     740                 }
     741                 
     742                 
     743                 if(station_change_four<=station_end)
     744                 {
     745                     
     746                     sql="select * from station where station_number>=?";
     747                     ps=conn.prepareStatement(sql);
     748                     ps.setInt(1, station_change_four);
     749                     rs=ps.executeQuery();
     750                     while(rs.next()&&station_number!=station_end)
     751                     {
     752                             sum++;
     753                             station_number = rs.getInt("station_number");
     754                             station_name = rs.getString("station_name");
     755                             station_change= rs.getInt("station_change");
     756                             station_main= rs.getInt("station_main");
     757                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     758                        
     759                     }
     760                 }
     761                 
     762                 if(station_change_four>=station_end)
     763                 {
     764                     sql="select * from station where station_number=?";    //起点站号
     765                     ps=conn.prepareStatement(sql);
     766                     for(int i1=station_change_four;i1>=station_end;i1--) 
     767                     {
     768                         ps.setInt(1, i1);
     769                         rs=ps.executeQuery();
     770                         if(rs.next()) 
     771                         {
     772                             sum++;
     773                             station_number = rs.getInt("station_number");
     774                             station_name = rs.getString("station_name");
     775                             station_change= rs.getInt("station_change");
     776                             station_main= rs.getInt("station_main");
     777                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     778                             
     779                         }
     780                     }
     781                 }
     782                 finally_start=station_start;
     783                  finally_end=station_end;
     784                  main_start_[thought_a]=main_start;
     785                     main_end_[thought_a]=main_end;
     786                     finally_start_[thought_a]=finally_start;
     787                     finally_end_[thought_a]=finally_end;
     788                  mid1[thought_a]=station_change_one;
     789                  mid2[thought_a]=station_change_two;
     790                  mid3[thought_a]=station_change_three;
     791                  mid4[thought_a]=station_change_four;
     792                  count[thought_a]=sum-2;
     793                 System.out.println(""+(sum-2));
     794             }
     795             
     796             //转两站1-2
     797             for(int i=1;i<7;i++)
     798             {
     799                 if(i==main_end||i==main_start)
     800                 {
     801                     continue;
     802                 }
     803                 
     804                 change_copy=2;
     805                 sql="select * from station where station_change=? and change_copy=?";    //中转站
     806                 ps=conn.prepareStatement(sql);
     807                 ps.setInt(1, 10*a+i);
     808                 ps.setInt(2, 1);
     809                 ResultSet bb=ps.executeQuery();
     810                 if(bb.next())
     811                 {
     812                     station_change_one_main=bb.getInt("station_main");
     813                     station_change_one=bb.getInt("station_number");
     814                     
     815                 }
     816                 sql="select * from station where station_change=? and change_copy=?";    //中转站2站号
     817                 ps=conn.prepareStatement(sql);
     818                 ps.setInt(1, 10*i+a);
     819                 ps.setInt(2, 1);
     820                 ResultSet cc=ps.executeQuery();
     821                 if(cc.next()) 
     822                 {
     823                     station_change_two_main=cc.getInt("station_main");
     824                     station_change_two=cc.getInt(1);
     825                     
     826                 }
     827                 
     828                 sql="select * from station where station_change=? and change_copy=?";    //中转站3站号
     829                 ps=conn.prepareStatement(sql);
     830                 ps.setInt(1, 10*station_change_two_main+c);
     831                 ps.setInt(2, change_copy);
     832                 ResultSet dd=ps.executeQuery();
     833                 if(dd.next()) 
     834                 {
     835                     station_change_three_main=dd.getInt("station_main");
     836                     station_change_three=dd.getInt(1);
     837                     
     838                 }
     839                 else
     840                 {
     841                     continue;
     842                 }
     843                 thought_a++;
     844                 sum=0;
     845                 System.out.println("-------------------------------------------------------------");
     846                 System.out.println("到站点"+i);
     847                 System.out.println("中转站"+"  "+station_change_one_main+"  "+station_change_one);
     848                 if(station_start<=station_change_one)
     849                 {
     850                     sql="select * from station where station_number>=?";
     851                     ps=conn.prepareStatement(sql);
     852                     ps.setInt(1, station_start);
     853                     rs=ps.executeQuery();
     854                     while(rs.next()&&station_number!=station_change_one)
     855                     {        
     856                             sum++;
     857                             station_number = rs.getInt("station_number");
     858                             station_name = rs.getString("station_name");
     859                             station_change= rs.getInt("station_change");
     860                             station_main= rs.getInt("station_main");
     861                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     862                     }
     863                 }
     864                 if(station_start>=station_change_one)
     865                 {
     866                     sql="select * from station where station_number=?";    //起点站号
     867                     ps=conn.prepareStatement(sql);
     868                     for(int i1=station_start;i1>=station_change_one;i1--) 
     869                     {
     870                         ps.setInt(1, i1);
     871                         rs=ps.executeQuery();
     872                         if(rs.next()) 
     873                         {
     874                             sum++;
     875                             station_number = rs.getInt("station_number");
     876                             station_name = rs.getString("station_name");
     877                             station_change= rs.getInt("station_change");
     878                             station_main= rs.getInt("station_main");
     879                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     880                         }
     881                     }
     882                 }
     883                 System.out.println("中转站2"+"  "+station_change_two_main+"  "+station_change_two);
     884                 System.out.println("中转站3"+"  "+station_change_three_main+"  "+station_change_three);
     885                 if(station_change_two<=station_change_three)
     886                 {
     887                     sql="select * from station where station_number>=?";
     888                     ps=conn.prepareStatement(sql);
     889                     ps.setInt(1,station_change_two);
     890                     rs=ps.executeQuery();
     891                     while(rs.next()&&station_number!=station_change_three)
     892                     {
     893                             sum++;
     894                             station_number = rs.getInt("station_number");
     895                             station_name = rs.getString("station_name");
     896                             station_change= rs.getInt("station_change");
     897                             station_main= rs.getInt("station_main");
     898                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     899                        
     900                     }
     901                 }
     902                 if(station_change_two>=station_change_three)
     903                 {
     904                     sql="select * from station where station_number=?";    
     905                     ps=conn.prepareStatement(sql);
     906                     for(int i1=station_change_two;i1>=station_change_three;i1--) 
     907                     {
     908                         ps.setInt(1, i1);
     909                         rs=ps.executeQuery();
     910                         if(rs.next()) 
     911                         {
     912                             sum++;
     913                             station_number = rs.getInt("station_number");
     914                             station_name = rs.getString("station_name");
     915                             station_change= rs.getInt("station_change");
     916                             station_main= rs.getInt("station_main");
     917                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     918                         }
     919                     }
     920                 }
     921                 
     922                 sql="select * from station where station_change=? and change_copy=?";    //中转站4站号
     923                 ps=conn.prepareStatement(sql);
     924                 ps.setInt(1, 10*c+station_change_three_main);
     925                 ps.setInt(2, change_copy);
     926                 ResultSet ee=ps.executeQuery();
     927                 if(ee.next()) 
     928                 {
     929                     station_change_four_main=ee.getInt("station_main");
     930                     station_change_four=ee.getInt(1);
     931                     System.out.println("中转站4"+"  "+station_change_four_main+"  "+station_change_four);
     932                 }
     933                 
     934                 
     935                 if(station_change_four<=station_end)
     936                 {
     937                     
     938                     sql="select * from station where station_number>=?";
     939                     ps=conn.prepareStatement(sql);
     940                     ps.setInt(1, station_change_four);
     941                     rs=ps.executeQuery();
     942                     while(rs.next()&&station_number!=station_end)
     943                     {
     944                             sum++;
     945                             station_number = rs.getInt("station_number");
     946                             station_name = rs.getString("station_name");
     947                             station_change= rs.getInt("station_change");
     948                             station_main= rs.getInt("station_main");
     949                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     950                        
     951                     }
     952                 }
     953                 
     954                 if(station_change_four>=station_end)
     955                 {
     956                     sql="select * from station where station_number=?";    //起点站号
     957                     ps=conn.prepareStatement(sql);
     958                     for(int i1=station_change_four;i1>=station_end;i1--) 
     959                     {
     960                         ps.setInt(1, i1);
     961                         rs=ps.executeQuery();
     962                         if(rs.next()) 
     963                         {
     964                             sum++;
     965                             station_number = rs.getInt("station_number");
     966                             station_name = rs.getString("station_name");
     967                             station_change= rs.getInt("station_change");
     968                             station_main= rs.getInt("station_main");
     969                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
     970                             
     971                         }
     972                     }
     973                 }
     974                 finally_start=station_start;
     975                  finally_end=station_end;
     976                  main_start_[thought_a]=main_start;
     977                     main_end_[thought_a]=main_end;
     978                     finally_start_[thought_a]=finally_start;
     979                     finally_end_[thought_a]=finally_end;
     980                  mid1[thought_a]=station_change_one;
     981                  mid2[thought_a]=station_change_two;
     982                  mid3[thought_a]=station_change_three;
     983                  mid4[thought_a]=station_change_four;
     984                  count[thought_a]=sum-2;
     985                 System.out.println(""+(sum-2));
     986             }
     987             
     988             
     989             
     990             //转两站2-2
     991             for(int i=1;i<7;i++)
     992             {
     993                 if(i==main_end||i==main_start)
     994                 {
     995                     continue;
     996                 }
     997                 
     998                 change_copy=2;
     999                 sql="select * from station where station_change=? and change_copy=?";    //中转站
    1000                 ps=conn.prepareStatement(sql);
    1001                 ps.setInt(1, 10*a+i);
    1002                 ps.setInt(2, change_copy);
    1003                 ResultSet bb=ps.executeQuery();
    1004                 if(bb.next())
    1005                 {
    1006                     station_change_one_main=bb.getInt("station_main");
    1007                     station_change_one=bb.getInt("station_number");
    1008                     
    1009                 }
    1010                 sql="select * from station where station_change=? and change_copy=?";    //中转站2站号
    1011                 ps=conn.prepareStatement(sql);
    1012                 ps.setInt(1, 10*i+a);
    1013                 ps.setInt(2, change_copy);
    1014                 ResultSet cc=ps.executeQuery();
    1015                 if(cc.next()) 
    1016                 {
    1017                     station_change_two_main=cc.getInt("station_main");
    1018                     station_change_two=cc.getInt(1);
    1019                     
    1020                 }
    1021                 
    1022                 sql="select * from station where station_change=? and change_copy=?";    //中转站3站号
    1023                 ps=conn.prepareStatement(sql);
    1024                 ps.setInt(1, 10*station_change_two_main+c);
    1025                 ps.setInt(2, change_copy);
    1026                 ResultSet dd=ps.executeQuery();
    1027                 if(dd.next()) 
    1028                 {
    1029                     station_change_three_main=dd.getInt("station_main");
    1030                     station_change_three=dd.getInt(1);
    1031                     
    1032                 }
    1033                 else
    1034                 {
    1035                     continue;
    1036                 }
    1037                 thought_a++;
    1038                 sum=0;
    1039                 System.out.println("-------------------------------------------------------------");
    1040                 System.out.println("到站点"+i);
    1041                 System.out.println("中转站"+"  "+station_change_one_main+"  "+station_change_one);
    1042                 if(station_start<=station_change_one)
    1043                 {
    1044                     sql="select * from station where station_number>=?";
    1045                     ps=conn.prepareStatement(sql);
    1046                     ps.setInt(1, station_start);
    1047                     rs=ps.executeQuery();
    1048                     while(rs.next()&&station_number!=station_change_one)
    1049                     {        
    1050                             sum++;
    1051                             station_number = rs.getInt("station_number");
    1052                             station_name = rs.getString("station_name");
    1053                             station_change= rs.getInt("station_change");
    1054                             station_main= rs.getInt("station_main");
    1055                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1056                     }
    1057                 }
    1058                 if(station_start>=station_change_one)
    1059                 {
    1060                     sql="select * from station where station_number=?";    //起点站号
    1061                     ps=conn.prepareStatement(sql);
    1062                     for(int i1=station_start;i1>=station_change_one;i1--) 
    1063                     {
    1064                         ps.setInt(1, i1);
    1065                         rs=ps.executeQuery();
    1066                         if(rs.next()) 
    1067                         {
    1068                             sum++;
    1069                             station_number = rs.getInt("station_number");
    1070                             station_name = rs.getString("station_name");
    1071                             station_change= rs.getInt("station_change");
    1072                             station_main= rs.getInt("station_main");
    1073                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1074                         }
    1075                     }
    1076                 }
    1077                 System.out.println("中转站2"+"  "+station_change_two_main+"  "+station_change_two);
    1078                 System.out.println("中转站3"+"  "+station_change_three_main+"  "+station_change_three);
    1079                 if(station_change_two<=station_change_three)
    1080                 {
    1081                     sql="select * from station where station_number>=?";
    1082                     ps=conn.prepareStatement(sql);
    1083                     ps.setInt(1,station_change_two);
    1084                     rs=ps.executeQuery();
    1085                     while(rs.next()&&station_number!=station_change_three)
    1086                     {
    1087                             sum++;
    1088                             station_number = rs.getInt("station_number");
    1089                             station_name = rs.getString("station_name");
    1090                             station_change= rs.getInt("station_change");
    1091                             station_main= rs.getInt("station_main");
    1092                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1093                        
    1094                     }
    1095                 }
    1096                 if(station_change_two>=station_change_three)
    1097                 {
    1098                     sql="select * from station where station_number=?";    
    1099                     ps=conn.prepareStatement(sql);
    1100                     for(int i1=station_change_two;i1>=station_change_three;i1--) 
    1101                     {
    1102                         ps.setInt(1, i1);
    1103                         rs=ps.executeQuery();
    1104                         if(rs.next()) 
    1105                         {
    1106                             sum++;
    1107                             station_number = rs.getInt("station_number");
    1108                             station_name = rs.getString("station_name");
    1109                             station_change= rs.getInt("station_change");
    1110                             station_main= rs.getInt("station_main");
    1111                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1112                         }
    1113                     }
    1114                 }
    1115                 
    1116                 sql="select * from station where station_change=? and change_copy=?";    //中转站4站号
    1117                 ps=conn.prepareStatement(sql);
    1118                 ps.setInt(1, 10*c+station_change_three_main);
    1119                 ps.setInt(2, 1);
    1120                 ResultSet ee=ps.executeQuery();
    1121                 if(ee.next()) 
    1122                 {
    1123                     station_change_four_main=ee.getInt("station_main");
    1124                     station_change_four=ee.getInt(1);
    1125                     System.out.println("中转站4"+"  "+station_change_four_main+"  "+station_change_four);
    1126                 }
    1127                 
    1128                 
    1129                 if(station_change_four<=station_end)
    1130                 {
    1131                     
    1132                     sql="select * from station where station_number>=?";
    1133                     ps=conn.prepareStatement(sql);
    1134                     ps.setInt(1, station_change_four);
    1135                     rs=ps.executeQuery();
    1136                     while(rs.next()&&station_number!=station_end)
    1137                     {
    1138                             sum++;
    1139                             station_number = rs.getInt("station_number");
    1140                             station_name = rs.getString("station_name");
    1141                             station_change= rs.getInt("station_change");
    1142                             station_main= rs.getInt("station_main");
    1143                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1144                        
    1145                     }
    1146                 }
    1147                 
    1148                 if(station_change_four>=station_end)
    1149                 {
    1150                     sql="select * from station where station_number=?";    //起点站号
    1151                     ps=conn.prepareStatement(sql);
    1152                     for(int i1=station_change_four;i1>=station_end;i1--) 
    1153                     {
    1154                         ps.setInt(1, i1);
    1155                         rs=ps.executeQuery();
    1156                         if(rs.next()) 
    1157                         {
    1158                             sum++;
    1159                             station_number = rs.getInt("station_number");
    1160                             station_name = rs.getString("station_name");
    1161                             station_change= rs.getInt("station_change");
    1162                             station_main= rs.getInt("station_main");
    1163                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1164                             
    1165                         }
    1166                     }
    1167                 }
    1168                 finally_start=station_start;
    1169                 finally_end=station_end;
    1170                 main_start_[thought_a]=main_start;
    1171                 main_end_[thought_a]=main_end;
    1172                 finally_start_[thought_a]=finally_start;
    1173                 finally_end_[thought_a]=finally_end;
    1174                 mid1[thought_a]=station_change_one;
    1175                 mid2[thought_a]=station_change_two;
    1176                 mid3[thought_a]=station_change_three;
    1177                 mid4[thought_a]=station_change_four;
    1178                 count[thought_a]=sum-2;
    1179                 System.out.println(""+(sum-2));
    1180             }
    1181         }
    1182             }
    1183             
    1184         
    1185         int min = count[1];
    1186         for(int s=1;s<thought_a;s++) 
    1187         {
    1188             System.out.println(count[s]);
    1189             if(min>count[s+1])
    1190             {
    1191                 min=count[s+1];
    1192             }
    1193         }
    1194         for(int s=1;s<=thought_a;s++)
    1195         {
    1196             if(min==count[s])
    1197             {
    1198                 thought_b=s;
    1199             }
    1200         }
    1201         finally_start=finally_start_[thought_b];
    1202         finally_end=finally_end_[thought_b];
    1203         main_start=main_start_[thought_b];
    1204         main_end=main_end_[thought_b];
    1205         finally_mid1=mid1[thought_b];
    1206         finally_mid2=mid2[thought_b];
    1207         finally_mid3=mid3[thought_b];
    1208         finally_mid4=mid4[thought_b];
    1209         System.out.println(min);
    1210         if(main_start==main_end)
    1211         {
    1212             if(finally_start<=finally_end)
    1213             {
    1214                 sql="select * from station where station_number>=?";
    1215                 ps=conn.prepareStatement(sql);
    1216                 ps.setInt(1, finally_start);
    1217                 rs=ps.executeQuery();
    1218                 while(rs.next()&&station_number!=finally_end)
    1219                 {
    1220                         
    1221                         station_number = rs.getInt("station_number");
    1222                         station_name = rs.getString("station_name");
    1223                         station_change= rs.getInt("station_change");
    1224                         station_main= rs.getInt("station_main");
    1225                         System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1226                 }
    1227                 
    1228                 
    1229             }
    1230             if(finally_start>=finally_end)
    1231             {
    1232                 sql="select * from station where station_number=?";    //起点站号
    1233                 ps=conn.prepareStatement(sql);
    1234                 for(int i1=finally_start;i1>=finally_end;i1--) 
    1235                 {
    1236                     ps.setInt(1, i1);
    1237                     rs=ps.executeQuery();
    1238                     if(rs.next()) 
    1239                     {
    1240                         station_number = rs.getInt("station_number");
    1241                         station_name = rs.getString("station_name");
    1242                         station_change= rs.getInt("station_change");
    1243                         station_main= rs.getInt("station_main");
    1244                         System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1245                     }
    1246                 }
    1247             }
    1248         }
    1249         else
    1250         {
    1251             if(finally_mid3==0)
    1252             {
    1253                 if(finally_start<=finally_mid1)
    1254                 {
    1255                     sql="select * from station where station_number>=?";
    1256                     ps=conn.prepareStatement(sql);
    1257                     ps.setInt(1, finally_start);
    1258                     rs=ps.executeQuery();
    1259                     while(rs.next()&&station_number!=finally_mid1)
    1260                     {
    1261                             
    1262                             station_number = rs.getInt("station_number");
    1263                             station_name = rs.getString("station_name");
    1264                             station_change= rs.getInt("station_change");
    1265                             station_main= rs.getInt("station_main");
    1266                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1267                     }
    1268                     
    1269                     
    1270                 }
    1271                 if(finally_start>=finally_mid1)
    1272                 {
    1273                     sql="select * from station where station_number=?";    //起点站号
    1274                     ps=conn.prepareStatement(sql);
    1275                     for(int i1=finally_start;i1>=finally_mid1;i1--) 
    1276                     {
    1277                         ps.setInt(1, i1);
    1278                         rs=ps.executeQuery();
    1279                         if(rs.next()) 
    1280                         {
    1281                             station_number = rs.getInt("station_number");
    1282                             station_name = rs.getString("station_name");
    1283                             station_change= rs.getInt("station_change");
    1284                             station_main= rs.getInt("station_main");
    1285                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1286                         }
    1287                     }
    1288                 }
    1289                  System.out.println("-------------------------------------------------------------");
    1290                 if(finally_end>=finally_mid2)
    1291                 {
    1292                     sql="select * from station where station_number>=?";
    1293                     ps=conn.prepareStatement(sql);
    1294                     ps.setInt(1, mid2[thought_b]);
    1295                     rs=ps.executeQuery();
    1296                     while(rs.next()&&station_number!=finally_end)
    1297                     {
    1298                             
    1299                             station_number = rs.getInt("station_number");
    1300                             station_name = rs.getString("station_name");
    1301                             station_change= rs.getInt("station_change");
    1302                             station_main= rs.getInt("station_main");
    1303                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1304                     }
    1305                     
    1306                     
    1307                 }
    1308                 if(finally_end<=finally_mid2)
    1309                 {
    1310                     sql="select * from station where station_number=?";    //起点站号
    1311                     ps=conn.prepareStatement(sql);
    1312                     for(int i1=finally_mid2;i1>=finally_end;i1--) 
    1313                     {
    1314                         ps.setInt(1, i1);
    1315                         rs=ps.executeQuery();
    1316                         if(rs.next()) 
    1317                         {
    1318                             station_number = rs.getInt("station_number");
    1319                             station_name = rs.getString("station_name");
    1320                             station_change= rs.getInt("station_change");
    1321                             station_main= rs.getInt("station_main");
    1322                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1323                         }
    1324                     }
    1325                 }
    1326                 
    1327             }
    1328             else
    1329             {
    1330                 
    1331                 if(finally_start<=finally_mid1)
    1332                 {
    1333                     sql="select * from station where station_number>=?";
    1334                     ps=conn.prepareStatement(sql);
    1335                     ps.setInt(1, finally_start);
    1336                     rs=ps.executeQuery();
    1337                     while(rs.next()&&station_number!=finally_mid1)
    1338                     {        
    1339                             
    1340                             station_number = rs.getInt("station_number");
    1341                             station_name = rs.getString("station_name");
    1342                             station_change= rs.getInt("station_change");
    1343                             station_main= rs.getInt("station_main");
    1344                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1345                     }
    1346                 }
    1347                 if(finally_start>=finally_mid1)
    1348                 {
    1349                     sql="select * from station where station_number=?";    //起点站号
    1350                     ps=conn.prepareStatement(sql);
    1351                     for(int i1=finally_start;i1>=finally_mid1;i1--) 
    1352                     {
    1353                         ps.setInt(1, i1);
    1354                         rs=ps.executeQuery();
    1355                         if(rs.next()) 
    1356                         {
    1357                             sum++;
    1358                             station_number = rs.getInt("station_number");
    1359                             station_name = rs.getString("station_name");
    1360                             station_change= rs.getInt("station_change");
    1361                             station_main= rs.getInt("station_main");
    1362                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1363                         }
    1364                     }
    1365                 }
    1366                 
    1367             
    1368                 if(finally_mid2<=finally_mid3)
    1369                 {
    1370                     sql="select * from station where station_number>=?";
    1371                     ps=conn.prepareStatement(sql);
    1372                     ps.setInt(1,mid2[thought_b]);
    1373                     rs=ps.executeQuery();
    1374                     while(rs.next()&&station_number!=finally_mid3)
    1375                     {
    1376                             station_number = rs.getInt("station_number");
    1377                             station_name = rs.getString("station_name");
    1378                             station_change= rs.getInt("station_change");
    1379                             station_main= rs.getInt("station_main");
    1380                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1381                        
    1382                     }
    1383                 }
    1384                 if(finally_mid2>=finally_mid3)
    1385                 {
    1386                     sql="select * from station where station_number=?";    
    1387                     ps=conn.prepareStatement(sql);
    1388                     for(int i1=finally_mid2;i1>=finally_mid3;i1--) 
    1389                     {
    1390                         ps.setInt(1, i1);
    1391                         rs=ps.executeQuery();
    1392                         if(rs.next()) 
    1393                         {
    1394                             sum++;
    1395                             station_number = rs.getInt("station_number");
    1396                             station_name = rs.getString("station_name");
    1397                             station_change= rs.getInt("station_change");
    1398                             station_main= rs.getInt("station_main");
    1399                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1400                         }
    1401                     }
    1402                 }
    1403                 
    1404                  System.out.println("-------------------------------------------------------------");
    1405                 if(finally_mid4<=finally_end)
    1406                 {
    1407                     
    1408                     sql="select * from station where station_number>=?";
    1409                     ps=conn.prepareStatement(sql);
    1410                     ps.setInt(1, finally_mid4);
    1411                     rs=ps.executeQuery();
    1412                     while(rs.next()&&station_number!=finally_end)
    1413                     {
    1414                             sum++;
    1415                             station_number = rs.getInt("station_number");
    1416                             station_name = rs.getString("station_name");
    1417                             station_change= rs.getInt("station_change");
    1418                             station_main= rs.getInt("station_main");
    1419                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1420                        
    1421                     }
    1422                 }
    1423                 
    1424                 if(finally_mid4>=finally_end)
    1425                 {
    1426                     sql="select * from station where station_number=?";   
    1427                     ps=conn.prepareStatement(sql);
    1428                     for(int i1=finally_mid4;i1>=finally_end;i1--) 
    1429                     {
    1430                         ps.setInt(1, i1);
    1431                         rs=ps.executeQuery();
    1432                         if(rs.next()) 
    1433                         {
    1434                             sum++;
    1435                             station_number = rs.getInt("station_number");
    1436                             station_name = rs.getString("station_name");
    1437                             station_change= rs.getInt("station_change");
    1438                             station_main= rs.getInt("station_main");
    1439                             System.out.println("线路:"+station_main+"  站号:"+station_number+" 站名:"+station_name+" 转站点:"+station_change);
    1440                            
    1441                         }
    1442                     }
    1443                 }
    1444             }
    1445         }
    1446         System.out.println(main_start+" "+finally_start+" "+main_end+" "+finally_end+" "+finally_mid1+" "+finally_mid2+" "+finally_mid3+" "+finally_mid4);
    1447         }
    1448         finally 
    1449         {
    1450             try 
    1451             {
    1452                 
    1453                  if(ps!=null)ps.close();
    1454                  if(conn!=null)conn.close();
    1455             }
    1456             catch(Exception e2) 
    1457             {
    1458                  e2.printStackTrace();
    1459             }
    1460         }
    1461     }
    1462     @SuppressWarnings("resource")
    1463     public static List<User> load(String aaa,String bbb) throws SQLException {  
    1464         
    1465         hightestfind(aaa,bbb);
    1466         Connection connection = Util.getConn();
    1467         String sql;
    1468         PreparedStatement preparedStatement = null;
    1469         ResultSet resultSet = null;
    1470         List<User> users = new ArrayList<User>();
    1471         User user = null;
    1472         try {
    1473             if(main_start==main_end)
    1474             {
    1475                 System.out.println(main_start+" "+main_end+" "+finally_start+"  "+finally_end);
    1476                 if(finally_start<=finally_end)
    1477                 {
    1478                     sql="select * from station where station_number between ? and ? order by station_number ASC";
    1479                     preparedStatement = connection.prepareStatement(sql);
    1480                     preparedStatement.setInt(1,finally_start);
    1481                     preparedStatement.setInt(2, finally_end);
    1482                 }
    1483                 else
    1484                 {
    1485                     sql="select * from station where station_number between ? and ? order by station_number desc";
    1486                     preparedStatement = connection.prepareStatement(sql);
    1487                     preparedStatement.setInt(1,finally_end);
    1488                     preparedStatement.setInt(2, finally_start);
    1489                 }
    1490                 resultSet = preparedStatement.executeQuery();
    1491                 while(resultSet.next()) {
    1492                     user = new User();
    1493                     user.setstation_change(resultSet.getInt("station_change"));
    1494                     user.setstation_main(resultSet.getInt("station_main"));
    1495                     user.setstation_name(resultSet.getString("station_name"));
    1496                     user.setstation_number(resultSet.getInt("station_number"));
    1497                     users.add(user);
    1498                 }
    1499             }
    1500             else
    1501             {
    1502                 if(finally_mid3==0)        //转一站
    1503                 {
    1504                     if(finally_start<=finally_mid1)
    1505                     {
    1506                         sql="select * from station where station_number between ? and ? order by station_number ASC";
    1507                         preparedStatement = connection.prepareStatement(sql);
    1508                         preparedStatement.setInt(1,finally_start);
    1509                         preparedStatement.setInt(2, finally_mid1);
    1510                     }
    1511                     else
    1512                     {
    1513                         sql="select * from station where station_number between ? and ? order by station_number desc";
    1514                         preparedStatement = connection.prepareStatement(sql);
    1515                         preparedStatement.setInt(1,finally_mid1);
    1516                         preparedStatement.setInt(2, finally_start);
    1517                     }
    1518                     resultSet = preparedStatement.executeQuery();
    1519                     while(resultSet.next()) {
    1520                         user = new User();
    1521                         user.setstation_change(resultSet.getInt("station_change"));
    1522                         user.setstation_main(resultSet.getInt("station_main"));
    1523                         user.setstation_name(resultSet.getString("station_name"));
    1524                         user.setstation_number(resultSet.getInt("station_number"));
    1525                         users.add(user);
    1526                     }
    1527                     
    1528                     if(finally_mid2<=finally_end)
    1529                     {
    1530                         sql="select * from station where station_number between ? and ? order by station_number ASC";
    1531                         preparedStatement = connection.prepareStatement(sql);
    1532                         preparedStatement.setInt(1,finally_mid2);
    1533                         preparedStatement.setInt(2, finally_end);
    1534                     }
    1535                     else
    1536                     {
    1537                         sql="select * from station where station_number between ? and ? order by station_number desc";
    1538                         preparedStatement = connection.prepareStatement(sql);
    1539                         preparedStatement.setInt(1,finally_end);
    1540                         preparedStatement.setInt(2, finally_mid2);
    1541                     }
    1542                     resultSet = preparedStatement.executeQuery();
    1543                     while(resultSet.next()) {
    1544                         user = new User();
    1545                         user.setstation_change(resultSet.getInt("station_change"));
    1546                         user.setstation_main(resultSet.getInt("station_main"));
    1547                         user.setstation_name(resultSet.getString("station_name"));
    1548                         user.setstation_number(resultSet.getInt("station_number"));
    1549                         users.add(user);
    1550                     }
    1551                 }
    1552                 if(finally_mid3!=0)
    1553                 {
    1554                     if(finally_start<=finally_mid1)
    1555                     {
    1556                         sql="select * from station where station_number between ? and ? order by station_number ASC";
    1557                         preparedStatement = connection.prepareStatement(sql);
    1558                         preparedStatement.setInt(1,finally_start);
    1559                         preparedStatement.setInt(2, finally_mid1);
    1560                     }
    1561                     else
    1562                     {
    1563                         sql="select * from station where station_number between ? and ? order by station_number desc";
    1564                         preparedStatement = connection.prepareStatement(sql);
    1565                         preparedStatement.setInt(1,finally_mid1);
    1566                         preparedStatement.setInt(2, finally_start);
    1567                     }
    1568                     resultSet = preparedStatement.executeQuery();
    1569                     while(resultSet.next()) {
    1570                         user = new User();
    1571                         user.setstation_change(resultSet.getInt("station_change"));
    1572                         user.setstation_main(resultSet.getInt("station_main"));
    1573                         user.setstation_name(resultSet.getString("station_name"));
    1574                         user.setstation_number(resultSet.getInt("station_number"));
    1575                         users.add(user);
    1576                     }
    1577 
    1578                     if(finally_mid2<=finally_mid3)
    1579                     {
    1580                         sql="select * from station where station_number between ? and ? order by station_number ASC";
    1581                         preparedStatement = connection.prepareStatement(sql);
    1582                         preparedStatement.setInt(1,finally_mid2);
    1583                         preparedStatement.setInt(2, finally_mid3);
    1584                     }
    1585                     else
    1586                     {
    1587                         sql="select * from station where station_number between ? and ? order by station_number desc";
    1588                         preparedStatement = connection.prepareStatement(sql);
    1589                         preparedStatement.setInt(1,finally_mid3);
    1590                         preparedStatement.setInt(2, finally_mid2);
    1591                     }
    1592                     resultSet = preparedStatement.executeQuery();
    1593                     while(resultSet.next()) {
    1594                         user = new User();
    1595                         user.setstation_change(resultSet.getInt("station_change"));
    1596                         user.setstation_main(resultSet.getInt("station_main"));
    1597                         user.setstation_name(resultSet.getString("station_name"));
    1598                         user.setstation_number(resultSet.getInt("station_number"));
    1599                         users.add(user);
    1600                     }
    1601                     if(finally_mid4<=finally_end)
    1602                     {
    1603                         sql="select * from station where station_number between ? and ? order by station_number ASC";
    1604                         preparedStatement = connection.prepareStatement(sql);
    1605                         preparedStatement.setInt(1,finally_mid4);
    1606                         preparedStatement.setInt(2, finally_end);
    1607                     }
    1608                     else
    1609                     {
    1610                         sql="select * from station where station_number between ? and ? order by station_number desc";
    1611                         preparedStatement = connection.prepareStatement(sql);
    1612                         preparedStatement.setInt(1,finally_end);
    1613                         preparedStatement.setInt(2, finally_mid4);
    1614                     }
    1615                     resultSet = preparedStatement.executeQuery();
    1616                     while(resultSet.next()) {
    1617                         user = new User();
    1618                         user.setstation_change(resultSet.getInt("station_change"));
    1619                         user.setstation_main(resultSet.getInt("station_main"));
    1620                         user.setstation_name(resultSet.getString("station_name"));
    1621                         user.setstation_number(resultSet.getInt("station_number"));
    1622                         users.add(user);
    1623                     }
    1624                 }
    1625             }
    1626             
    1627         } catch (SQLException h) {
    1628             // TODO Auto-generated catch block
    1629             h.printStackTrace();
    1630         }finally {
    1631             Util.close(resultSet);
    1632             Util.close(preparedStatement);
    1633             Util.close(connection);
    1634         }
    1635         return  users;
    1636     }
    1637 
    1638     
    1639     public static void main(String[] args) throws SQLException {
    1640     LoginerDaoImpl lo=new LoginerDaoImpl();
    1641 //        lo.load("省博物馆","长安医院");
    1642 //    hightestfind("常青园","和平医院"); 
    1643         hightestfind("和平医院","东杜庄"); 
    1644         
    1645 //        load("省博物馆","新百广场");
    1646 //        
    1647 //    List<User> users = new ArrayList<User>();
    1648 //    User user=new User();
    1649 //    users=load("土贤庄","海世界");
    1650 //    for(User u:users) { 
    1651 //
    1652 //        u.getstation_main();
    1653 //        u.getstation_number(); 
    1654 //        u.getstation_name();
    1655 //        u.getstation_change();
    1656 //        System.out.println( u.getstation_name());
    1657 //    }
    1658 //    users=load("河北科技大学","涂料厂");
    1659 //    for(User u:users) { 
    1660 //
    1661 //        u.getstation_main();
    1662 //        u.getstation_number(); 
    1663 //        u.getstation_name();
    1664 //        u.getstation_change();
    1665 //        System.out.println( u.getstation_name());
    1666 //    }
    1667 //    users=load("河北科技大学","涂料厂");
    1668 //    for(User u:users) { 
    1669 //
    1670 //        u.getstation_main();
    1671 //        u.getstation_number(); 
    1672 //        u.getstation_name();
    1673 //        u.getstation_change();
    1674 //        System.out.println( u.getstation_name());
    1675 //    }
    1676 
    1677     }
    1678     
    1679 }
  • 相关阅读:
    C++ 命名管道示例
    C#模块初始化注入
    【Oracle】存储过程写法小例子
    【Kettle】4、SQL SERVER到SQL SERVER数据转换抽取实例
    【Kettle】3、数据源连接配置
    【Kettle】2、文件夹与界面介绍
    【Kettle】1、简单介绍
    【Kettle】8、变量参数传递介绍
    【Oracle】DBMS_STATS.GATHER_TABLE_STATS详解
    【Oracle】DBMS_STATS.GATHER_SCHEMA_STATS详解
  • 原文地址:https://www.cnblogs.com/zlc364624/p/10651999.html
Copyright © 2020-2023  润新知