当前位置 : 主页 > 编程语言 > c++ >

传入要更新的表名称,列名及其要更新的值自动获取updatesql语句

来源:互联网 收集:自由互联 发布时间:2021-06-30
获取更新语句的代码 public static String getUpdateSqlSentence(String tableName, Map mapValueKey, List list) { StringBuffer buffer=new StringBuffer(); if (tableName==null||mapValueKey==null||mapValueKey.size()==0) { return ""; } buff
获取更新语句的代码
public static String getUpdateSqlSentence(String tableName, Map
 
   mapValueKey, List
  
    list) { StringBuffer buffer=new StringBuffer(); if (tableName==null||mapValueKey==null||mapValueKey.size()==0) { return ""; } buffer.append(" update "+tableName+" SET "); for (Map.Entry
   
     entry : mapValueKey.entrySet()) { buffer.append(entry.getKey()).append("='").append(entry.getValue()).append("',"); } String sql=buffer.toString().substring(0, buffer.toString().length()-1); String pksString=" where id in ("+getPksMosaicString(list)+")"; sql+=pksString; return sql; } public static String getPksMosaicString(List
    
      pks){ if (null==pks||pks.size()==0) { return "''"; }else { StringBuilder builder=new StringBuilder(); for (String pk : pks) { builder.append("'").append(pk).append("'").append(",") ; } return builder.toString().substring(0, builder.toString().length()-1); } }
    
   
  
 
网友评论