zoukankan      html  css  js  c++  java
  • JdbcTemplate使用

    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.jdbc.core.RowCallbackHandler;
    import org.springframework.stereotype.Repository;
    
    import javax.annotation.Resource;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    
    @Repository
    public class WaterDataDao {
    
        @Resource
        private JdbcTemplate jdbcTemplate;
    
        public List<WaterDataEntity> getAll(){
            StringBuffer sql = new StringBuffer();
            sql.append(" SELECT TT1.STCD,TT1.STNM,TT1.LGTD,TT1.LTTD,TT2.Z,TT2.TM FROM")
                    .append("( SELECT t.STCD,t.STNM,t.LGTD,t.LTTD FROM ST_STBPRP_B t WHERE t.ADMAUTH!='气象' and t.RVNM='长江') TT1,")
                    .append("( SELECT XX.STCD,XX.tm,XX.z FROM ST_RIVER_R XX,")
                    .append("( SELECT t.STCD, "MAX"(t.TM) maxTM FROM ST_RIVER_R t")
                    .append(" WHERE t.TM < SYSDATE AND t.TM > (SYSDATE - 3/24)")
                    .append(" GROUP BY t.STCD) YY")
                    .append(" WHERE XX.STCD=YY.STCD AND XX.TM = YY.MAXTM) TT2 ")
                    .append(" WHERE TT1.STCD = TT2.STCD");
    
    //        RowMapper<WaterDataEntity> rowMapper = new BeanPropertyRowMapper<>(WaterDataEntity.class);
    //        return jdbcTemplate.queryForObject(sql.toString(),rowMapper);
    
            final List<WaterDataEntity> waterDataList = new ArrayList<WaterDataEntity>();//在内部匿名类中使用
    
            jdbcTemplate.query(sql.toString(), new RowCallbackHandler() {
                @Override
                public void processRow(ResultSet rs) throws SQLException {
                    // TODO Auto-generated method stub
                    WaterDataEntity waterDataEntity = new WaterDataEntity();
                    waterDataEntity.setStcd(rs.getString("STCD"));
                    waterDataEntity.setStnm(rs.getString("STNM"));
                    waterDataEntity.setLgtd(rs.getBigDecimal("LGTD"));
                    waterDataEntity.setLttd(rs.getBigDecimal("LTTD"));
                    waterDataEntity.setZ(rs.getBigDecimal("Z"));
                    waterDataEntity.setTm(rs.getString("TM"));
                    waterDataList.add(waterDataEntity);
                }
            });
            return  waterDataList;
        }
    
    }
  • 相关阅读:
    MSP430G2553 4x4矩阵键盘
    数论 (1)
    吐血分享一款免费看所有付费影视的app,不好用来石欠我
    Nginx如何部署静态web项目
    SpringBoot-RestTemplate实现调用第三方API
    信息收集小技巧
    kali常用命令
    kali中的Firefox改中文
    反射与注解
    MyBatis-Plus 基本用法
  • 原文地址:https://www.cnblogs.com/unique1319/p/7691557.html
Copyright © 2011-2022 走看看