zoukankan      html  css  js  c++  java
  • DriverManager 查询数据库拼接BUFFER

            Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;
            try{
                Class.forName("com.mysql.jdbc.Driver");
                 String dbNmae = "logall"+params.get("dbName");
                 String dbIp = ConfigUtil.pro.get("linkLogIp").toString();
                 String linkCloudSql = "jdbc:mysql://"+dbIp+"/"+dbNmae;
                 String linkCloudUsername =ConfigUtil.pro.get("linkLogIpUsername").toString();
                 String linkCloudPassword =ConfigUtil.pro.get("linkLogIpPassword").toString();
                 
                 
                 conn = DriverManager
                         .getConnection(
                                 linkCloudSql,linkCloudUsername, linkCloudPassword);
                 stmt = conn.createStatement();
                 PreparedStatement ps=null;
                 
                 StringBuffer buffer = new StringBuffer("SELECT `id`,`idc`,`flag`,`cmdStartTime`,`json`,`cmdEndTime`,`retValue`,`crmId`,CASE WHEN `fName` = '' OR `fName` IS NULL THEN `idsid` ELSE `fName` END `fName`,`insertTime`,TIMESTAMPDIFF(FRAC_SECOND,cmdstarttime,cmdendtime )  AS duration FROM  log_controlresult  WHERE idc = ? and flag in ('BlueToothControl','carControlNew')");
                 if(params.get("ret") != null && StringUtils.isNoneEmpty(params.get("ret").toString())){
                     buffer.append("and retValue=?");
                 }
                 buffer.append(" order by crmid desc");
                 buffer.append(" LIMIT "+params.get("startIndex")+","+params.get("pageSize"));
                 
                 
                 
                 ps=(PreparedStatement) conn.prepareStatement(buffer.toString());
                  ps.setString(1, params.get("idc").toString());
    
                  
                  if(params.get("ret") != null && StringUtils.isNoneEmpty(params.get("ret").toString())){
                     ps.setString(2, params.get("ret").toString());
                 }
                 
                 log.info("控制历史sql:"+buffer.toString());
                  rs = ps.executeQuery();
                 while(rs.next())
                 {
                     controlresult cresult = new controlresult();
                     cresult.setId(rs.getLong("id"));
                     cresult.setIdc(rs.getString("idc"));
                     cresult.setFlag(rs.getString("flag"));
                     cresult.setCmdStartTime(rs.getTimestamp("cmdStartTime"));
                     cresult.setJson(rs.getString("json"));
                     cresult.setCmdEndTime(rs.getTimestamp("cmdEndTime"));
                     cresult.setRetValue(rs.getString("retValue"));
                     cresult.setCrmId(rs.getLong("crmId"));
                     cresult.setfName(rs.getString("fName"));
                     cresult.setInsertTime(rs.getTimestamp("insertTime"));
                     cresult.setDuration(rs.getInt("duration"));
                     cresult.setCmdName(GetSendTypeNameByJson(cresult.getJson()));
                     resultList.add(cresult);
                 }
            }
  • 相关阅读:
    Windows安装nginx服务
    高血压食谱 芹菜苦瓜可以降压吗
    非IT,零经验,零基础怎么备考信息系统项目管理师/高项考试?
    为什么要用urlencode()函数进行url编码
    Redis哨兵机制
    Qt 自定义QToolButton 自己互斥同时工具按钮之间实现互斥
    QItemSelectionModel获取QModelIndexList程序崩溃
    Qt QListView scrollTo定位指定项 和 LayoutMode布局的简单用法
    Sublime Text3 离线安装中文插件
    VSCODE导出PDF的数学公式
  • 原文地址:https://www.cnblogs.com/cuijinlong/p/7244845.html
Copyright © 2011-2022 走看看