结队作业-地铁查询系统(2)

dao.java: package Date; import Model.LineModel; import java.sql.*; import java.util.ArrayList; import java.util.List; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; public class Dao { public final String U = "jdbc:mysql://localhost:3306/db?&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=true"; public final String UName = "root"; public final String PassWord = ""; public LineModel selectkluxian(int no1) { PreparedStatement ps = null; Connection con = null; LineModel kc= new LineModel(); List<String> station = new ArrayList<>(); ResultSet rs = null; try { Class.forName("com.mysql.cj.jdbc.Driver"); con = DriverManager.getConnection(U, UName, PassWord); String sql = "select * from line where no1 =?"; ps = con.prepareStatement(sql); ps.setInt(1, no1); rs = ps.executeQuery(); int count = 0; while(rs.next()) { count++; //System.out.println(count); int ID=rs.getInt("ID"); String name=rs.getString("name"); //System.out.println(name); int no=rs.getInt("no1"); if(count == 1) { kc.setLineName(no + "号线"); } station.add(name); //list.add(kc); } kc.setStations(station); return kc; }catch (ClassNotFoundException e) { e.printStackTrace(); }catch (SQLException e) { e.printStackTrace(); }catch (Exception e) { e.printStackTrace(); }finally { try { if(rs!= null) rs.close(); if(ps!= null) ps.close(); if(con!= null) con.close(); } catch (SQLException e) { e.printStackTrace(); } } return kc; } public List<String> selectzhantai(String name) { PreparedStatement ps = null; Connection con = null; LineModel kc= new LineModel(); List<String> station = new ArrayList<>(); List<String> s = new ArrayList<>(); ResultSet rs = null; try { Class.forName("com.mysql.cj.jdbc.Driver"); con = DriverManager.getConnection(U, UName, PassWord); String sql = "select * from line where name =?"; ps = con.prepareStatement(sql); ps.setString(1, name); rs = ps.executeQuery(); int count = 0; while(rs.next()) { String tname=rs.getString("name"); int no = rs.getInt("no1"); //System.out.println(name); s.add(no+"号线"+" "); //list.add(kc); } return s; }catch (ClassNotFoundException e) { e.printStackTrace(); }catch (SQLException e) { e.printStackTrace(); }catch (Exception e) { e.printStackTrace(); }finally { try { if(rs!= null) rs.close(); if(ps!= null) ps.close(); if(con!= null) con.close(); } catch (SQLException e) { e.printStackTrace(); } } return s; } public List<String> selectxianlu2(int no1) { PreparedStatement ps = null; Connection con = null; List<String> station = new ArrayList<>(); List<String> s = new ArrayList<>(); ResultSet rs = null; try { Class.forName("com.mysql.cj.jdbc.Driver"); con = DriverManager.getConnection(U, UName, PassWord); String sql = "select * from line where =?"; ps = con.prepareStatement(sql); ps.setInt(1, no1); rs = ps.executeQuery(); int count = 0; while(rs.next()) { String name=rs.getString("name"); station.add(name); //list.add(kc); } return station; }catch (ClassNotFoundException e) { e.printStackTrace(); }catch (SQLException e) { e.printStackTrace(); }catch (Exception e) { e.printStackTrace(); }finally { try { if(rs!= null) rs.close(); if(ps!= null) ps.close(); if(con!= null) con.close(); } catch (SQLException e) { e.printStackTrace(); } } return station; }

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?