• util之sql拼接工具


    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    /**
     * @Author crd
     * @Date 2020-11-4 下午5:52:35
     * @Version 1.0 业务说明:主要用于oracle拼接sql,handleNull方法的参数说明,第二个布尔值是指是否需要添加逗号
     * 
     */
    public  class SqlAddUtil {
        public static String handleNull(Date d, Boolean isNeedComma) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String s = null;
            if (d != null) {
                if (isNeedComma) {
                    s = "to_date('" + sdf.format(d) + "', 'YYYYMMdd')" + ",";
                } else {
                    s = "to_date('" + sdf.format(d) + "', 'YYYYMMdd')";
                }
            } else {
                if (isNeedComma) {
                    s = null + ",";
                } else {
                    s = null;
                }
            }
            return s;
        }
    
        public static String handleNull(String str, Boolean isNeedComma) {
            String s = null;
            if (str != null) {
                if (isNeedComma) {
                    s = "'" + str + "'" + ",";
                } else {
                    s = "'" + str + "'";
                }
            } else {
                if (isNeedComma) {
                    s = null + ",";
                } else {
                    s = null;
                }
            }
    
            return s;
        }
    
        public static String handleNull(Double d, Boolean isNeedComma) {
            String s = "";
            if (d != null) {
    
                if (isNeedComma) {
                    s = d + ",";
                } else {
                    s = d + "";
                }
    
            } else {
                if (isNeedComma) {
                    s = null + ",";
                } else {
                    s = null;
                }
            }
            return s;
        }
    
        public static String handleNull(Float f, Boolean isNeedComma) {
            String s = "";
            if (f != null) {
                if (isNeedComma) {
                    s = f + ",";
                } else {
                    s = f + "";
                }
            } else {
                if (isNeedComma) {
                    s = null + ",";
                } else {
                    s = null;
                }
            }
            return s;
        }
    
        public static String handleNull(Long l, Boolean isNeedComma) {
            String s = "";
            if (l != null) {
    
                if (isNeedComma) {
                    s = l + ",";
                } else {
                    s = l + "";
                }
            } else {
                if (isNeedComma) {
                    s = null + ",";
                } else {
                    s = null;
                }
            }
            return s;
        }
    
        public static String handleNull(Integer i, Boolean isNeedComma) {
            String s = "";
            if (i != null) {
    
                if (isNeedComma) {
                    s = i + ",";
                } else {
                    s = i + "";
                }
            } else {
                if (isNeedComma) {
                    s = null + ",";
                } else {
                    s = null;
                }
            }
            return s;
        }
    
    }

    功能:主要用于oracle拼接sql,handleNull方法的参数说明,第二个布尔值是指是否需要添加逗号

    方法

    使用列子:

            String sql = "INSERT INTO W_FHYCGZ(MY_ID_,WDID,RQ,XQ,SJWDZG,SJWDZD,TQ,FHID,ZDFHZG,ZDFHZD,TDFHZG,TDFHZD,QWGDL,ZBGDL,ZDEMSGDFH,TDXSDDL,ZDTDXSDDL,ZDFDL,ZXFDL,ZDGFDL,GF14SDL,BZ,ZT,BYZD,BYZDDATE) VALUES " 
                            + "("   + handleNull(e.getMyId(),true) 
                                    + handleNull(e.getWdid(),true) 
                                    + handleNull(e.getRq(),true)  
                                    + handleNull(e.getXq(),true)  
                                    + handleNull(e.getSjwdzg(),true)  
                                    + handleNull(e.getSjwdzd(),true) 
                                    + handleNull(e.getTq(),true)  
                                    + handleNull(e.getFhid(),true)  
                                    + handleNull(e.getZdfhzg(),true)  
                                    + handleNull(e.getZdfhzd(),true)
                                    + handleNull(e.getTdfhzg(),true) 
                                    + handleNull(e.getTdfhzd(),true)
                                    + handleNull(e.getQwgdl(),true) 
                                    + handleNull(e.getZbgdl(),true)  
                                    + handleNull(e.getZdemsgdfh(),true)  
                                    + handleNull(e.getTdxsddl(),true)  
                                    + handleNull(e.getZdtdxsddl(),true)  
                                    + handleNull(e.getZdfdl(),true)  
                                    + handleNull(e.getZxfdl(),true)  
                                    + handleNull(e.getZdgfdl(),true)  
                                    + handleNull(e.getGf14sdl(),true)  
                                    + handleNull(e.getBz(),true)  
                                    + handleNull(e.getZt(),true)  
                                    + handleNull(e.getByzd(),true) 
                                    + handleNull(e.getByzddate(),false) 
                                    + ")";
                            System.out.println("==================================================="+sql);
                            jdbcTemplate.execute(sql);
  • 相关阅读:
    并查集基本操作及其优化
    POJ-3159.Candies.(差分约束 + Spfa)
    差分约束和最短路径(算法导论)
    POJ-3660.Cow Contest(有向图的传递闭包)
    Floyd-Warshall算法计算有向图的传递闭包
    深入理解链式前向星
    POJ-1860.CurrencyExchange(Spfa判断负环模版题)
    HDU-4725.TheShortestPathinNyaGraph(最短路 + 建图)
    POJ-3268.SilverCowParty.(最短路 + 图的转置)
    POJ-1797.HeavyTransportation(最长路中的最小权值)
  • 原文地址:https://www.cnblogs.com/rdchen/p/13927188.html
Copyright © 2020-2023  润新知