随笔 - 79  文章 - 0  评论 - 0  阅读 - 3227

第五周星期三每日总结

   今日完成第一次结对作业部分查询功能的开发,简单实现了线路查询的功能,对于站点查询,原理与线路查询相同,只需要顺便检索上一站与下一站的站点信息。至于换乘查询需要使用一定的算法实现。

线路查询界面:

 

 查询结果界面:

 

 地铁类:

复制代码
  1 package com.part.bean;
  2 
  3 import java.sql.*;
  4 
  5 public class Subway {
  6     private String linenumber;
  7     private String Id;
  8     private String name;
  9     private String message;
 10 
 11 
 12     public String getLinenumber() {
 13         return linenumber;
 14     }
 15 
 16     public void setLinenumber(String linenumber) {
 17         this.linenumber = linenumber;
 18     }
 19 
 20     public String getId() {
 21         return Id;
 22     }
 23 
 24     public void setId(String id) {
 25         Id = id;
 26     }
 27 
 28     public String getName() {
 29         return name;
 30     }
 31 
 32     public void setName(String name) {
 33         this.name = name;
 34     }
 35 
 36     public String getMessage() {
 37         return message;
 38     }
 39 
 40     public void setMessage(String message) {
 41         this.message = message;
 42     }
 43 
 44     public Subway() {
 45     }
 46     public Connection getConnection()//连接数据库
 47     {
 48         try {
 49             Class.forName("com.mysql.cj.jdbc.Driver");
 50             //System.out.println("加载驱动成功");
 51         } catch (ClassNotFoundException e) {
 52             e.printStackTrace();
 53         }
 54         String user = "root";
 55         String password = "352204";
 56         String url = "jdbc:mysql://localhost:3306/querry?useSSL=false&serverTimezone=GMT&characterEncoding=utf-8&autoReconnect=true";
 57         Connection con = null;
 58         try {
 59             con = DriverManager.getConnection(url, user, password);
 60             //System.out.println("数据库连接成功");
 61         } catch (SQLException e) {
 62             e.printStackTrace();
 63         }
 64         return con;
 65     }
 66     public boolean isSame(String s) {
 67         Connection connection = getConnection();
 68         PreparedStatement preparedStatement = null;
 69         ResultSet rs = null;
 70         try {
 71             String sql = "select * from subway";
 72             preparedStatement = connection.prepareStatement(sql);
 73             rs = preparedStatement.executeQuery();
 74             while (rs.next()) {
 75                 if (s.equals(rs.getObject(1)))
 76                     return true;
 77             }
 78             //preparedStatement.executeUpdate();
 79         } catch (SQLException e) {
 80             e.printStackTrace();
 81         } finally {
 82             close(rs);
 83             close(preparedStatement);
 84             close(connection);
 85         }
 86         return false;
 87     }
 88 
 89 
 90     public void close(Connection con) {
 91         try {
 92             if (con != null) {
 93                 con.close();
 94             }
 95         } catch (SQLException e) {
 96             e.printStackTrace();
 97         }
 98     }
 99 
100     public void close(PreparedStatement preparedStatement) {
101         try {
102             if (preparedStatement != null) {
103                 preparedStatement.close();
104             }
105         } catch (SQLException e) {
106             e.printStackTrace();
107         }
108     }
109 
110     public void close(ResultSet resultSet) {
111         try {
112             if (resultSet != null) {
113                 resultSet.close();
114             }
115         } catch (SQLException e) {
116             e.printStackTrace();
117         }
118     }
119 }package com.part.bean;
120 
121 import java.sql.*;
122 
123 public class Subway {
124     private String linenumber;
125     private String Id;
126     private String name;
127     private String message;
128 
129     public String getLinenumber() {
130         return linenumber;
131     }
132 
133     public void setLinenumber(String linenumber) {
134         this.linenumber = linenumber;
135     }
136 
137     public String getId() {
138         return Id;
139     }
140 
141     public void setId(String id) {
142         Id = id;
143     }
144 
145     public String getName() {
146         return name;
147     }
148 
149     public void setName(String name) {
150         this.name = name;
151     }
152 
153     public String getMessage() {
154         return message;
155     }
156 
157     public void setMessage(String message) {
158         this.message = message;
159     }
160 
161     public Subway() {
162     }
163     public Connection getConnection()//连接数据库
164     {
165         try {
166             Class.forName("com.mysql.cj.jdbc.Driver");
167             //System.out.println("加载驱动成功");
168         } catch (ClassNotFoundException e) {
169             e.printStackTrace();
170         }
171         String user = "root";
172         String password = "352204";
173         String url = "jdbc:mysql://localhost:3306/querry?useSSL=false&serverTimezone=GMT&characterEncoding=utf-8&autoReconnect=true";
174         Connection con = null;
175         try {
176             con = DriverManager.getConnection(url, user, password);
177             //System.out.println("数据库连接成功");
178         } catch (SQLException e) {
179             e.printStackTrace();
180         }
181         return con;
182     }
183     public boolean isSame(String s) {
184         Connection connection = getConnection();
185         PreparedStatement preparedStatement = null;
186         ResultSet rs = null;
187         try {
188             String sql = "select * from subway";
189             preparedStatement = connection.prepareStatement(sql);
190             rs = preparedStatement.executeQuery();
191             while (rs.next()) {
192                 if (s.equals(rs.getObject(1)))
193                     return true;
194             }
195             //preparedStatement.executeUpdate();
196         } catch (SQLException e) {
197             e.printStackTrace();
198         } finally {
199             close(rs);
200             close(preparedStatement);
201             close(connection);
202         }
203         return false;
204     }
205 
206 
207     public void close(Connection con) {
208         try {
209             if (con != null) {
210                 con.close();
211             }
212         } catch (SQLException e) {
213             e.printStackTrace();
214         }
215     }
216 
217     public void close(PreparedStatement preparedStatement) {
218         try {
219             if (preparedStatement != null) {
220                 preparedStatement.close();
221             }
222         } catch (SQLException e) {
223             e.printStackTrace();
224         }
225     }
226 
227     public void close(ResultSet resultSet) {
228         try {
229             if (resultSet != null) {
230                 resultSet.close();
231             }
232         } catch (SQLException e) {
233             e.printStackTrace();
234         }
235     }
236 }
复制代码

 

posted on   樱华旧梦  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示