zoukankan      html  css  js  c++  java
  • 毕业设计-1.13

    情况概述:

      今天完成了接口类的实现,并完成了简单测试。

    代码如下:

    WeatherDaoImpl.Java

    package com.zlc.dao.impl;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    
    import com.mysql.jdbc.Statement;
    /**  
    * @author Zhao Lucang
    * @version 创建时间:2021年2月26日 下午4:07:57  
    * 类说明  
    */
    import com.zlc.dao.IWeatherDao;
    import com.zlc.entity.WeatherBean;
    import com.zlc.entity.WeatherCountBean;
    import com.zlc.util.CommonMethod;
    
    public class WeatherDaoImpl implements IWeatherDao {
        Connection conn = null;
        PreparedStatement ps = null;
    
        // 查询此ID是否存在
        @Override
        public boolean isExist(int ID) {
            // TODO Auto-generated method stub
            return queryWeatherByID(ID) == null ? false : true;
        }
    
        // 根据编号查询天气
        @SuppressWarnings("restriction")
        @Override
        public WeatherBean queryWeatherByID(int ID) {
            WeatherBean weathers = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            String sql = "SELECT * FROM table_city_degree_2011 WHERE ID=?";
            // System.out.println(sql);
            try {
                Object[] params = { ID };
                rs = CommonMethod.executeQuery(sql, params);
                if (rs.next()) {
                    int id = rs.getInt("ID");
                    String province = rs.getString("Province");
                    String city = rs.getString("City");
                    int date = rs.getInt("Date");
                    String week = rs.getString("Week");
                    int mind = rs.getInt("MinD");
                    int maxd = rs.getInt("MaxD");
                    String weather = rs.getString("Weather");
                    String winddirection = rs.getString("WindDirection");
                    String windforce = rs.getString("WindForce");
                    weathers = new WeatherBean(id, province, city, date, week, mind, maxd, weather, winddirection,
                            windforce);
                }
                return weathers;
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return null;
            } finally {
                try {
                    CommonMethod.closeAll(rs, (Statement) ps, CommonMethod.conn);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    
        // 根据地点,时间查询
        @SuppressWarnings("restriction")
        @Override
        public WeatherBean queryWeatherByCityDate(String City, int Date) {
            WeatherBean weathers = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            String sub_date = String.valueOf(Date).substring(0, 4);
            String sql = "SELECT * FROM table_city_degree_" + sub_date + " WHERE City=? AND Date=?";
            // System.out.println(sql);
            try {
                Object[] params = { City, Date };
                rs = CommonMethod.executeQuery(sql, params);
                if (rs.next()) {
                    int id = rs.getInt("ID");
                    String province = rs.getString("Province");
                    String city = rs.getString("City");
                    int date = rs.getInt("Date");
                    String week = rs.getString("Week");
                    int mind = rs.getInt("MinD");
                    int maxd = rs.getInt("MaxD");
                    String weather = rs.getString("Weather");
                    String winddirection = rs.getString("WindDirection");
                    String windforce = rs.getString("WindForce");
    
                    weathers = new WeatherBean(id, province, city, date, week, mind, maxd, weather, winddirection,
                            windforce);
                }
                return weathers;
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return null;
            } finally {
                try {
                    CommonMethod.closeAll(rs, (Statement) ps, CommonMethod.conn);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    
        // 根据时间遍历全国
        @SuppressWarnings("restriction")
        @Override
        public List<WeatherBean> queryAllWeathersByDate(int Date) {
            // TODO Auto-generated method stub
            PreparedStatement ps = null;
            ResultSet rs = null;
            String sub_date = String.valueOf(Date).substring(0, 4);
            String sql = "SELECT * FROM table_city_degree_" + sub_date + " WHERE Date=?";
            List<WeatherBean> weathers = new ArrayList<WeatherBean>();
            // System.out.println(sql);
            try {
                Object[] params = { Date };
                rs = CommonMethod.executeQuery(sql, params);
                while (rs.next()) {
                    // 实例化StudentBean
                    WeatherBean weather = new WeatherBean();
                    weather.setID(rs.getInt("ID"));
                    weather.setProvince(rs.getString("Province"));
                    weather.setCity(rs.getString("City"));
                    weather.setDate(rs.getInt("Date"));
                    weather.setWeek(rs.getString("Week"));
                    weather.setMinD(rs.getInt("MinD"));
                    weather.setMaxD(rs.getInt("MaxD"));
                    weather.setWeather(rs.getString("Weather"));
                    weather.setWindDirection(rs.getString("WindDirection"));
                    weather.setWindForce(rs.getString("WindForce"));
                    weathers.add(weather);
                }
                return weathers;
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return null;
            } finally {
                try {
                    CommonMethod.closeAll(rs, (Statement) ps, CommonMethod.conn);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
  • 相关阅读:
    CSS3 背景
    CSS3 边框
    CSS3中的transform变形
    兼容IE与firefox火狐的回车事件(js与jquery)
    JS相关链接
    JS操作DOM元素属性和方法
    用js给html设置style
    JavaScript数学函数(一)
    [JS] 如何清空file input框 [整理]
    未在本地计算机上注册Microsoft.ACE.OLEDB.12.0提供程序(Oledb)
  • 原文地址:https://www.cnblogs.com/zlc364624/p/14461008.html
Copyright © 2011-2022 走看看