2023年8月3日发(作者:)
JAVA通过Map拼接SQL语句(InsertUpdate语句)package ;import ;import ls;import Utils;public class SQLUtils {
/** * 通过Map拼接Insert SQL语句 *
* @param tableName * @param dataMap * @return */ public static String genSqlInsert(String tableName, Map
//⽣成INSERT INTO table(field1,field2) 部分 StringBuffer sbField = new StringBuffer(); //⽣成VALUES('value1','value2') 部分 StringBuffer sbValue = new StringBuffer();
("INSERT INTO " + rCase() + "("); for(
("`" + mapKey + "`,"); ("'" + mapValue + "',"); }
sbField = LastChar(sbField); sbValue = LastChar(sbValue); return ng() + ") VALUES(" + ng() + ")"; }
/** * 通过Map拼接Update SQL语句 *
* @param tableName * @param operation * @param dataMap * @return */ public static String genSqlUpdate(String tableName, Map
String idColumn = (); String idValue = (idColumn);
StringBuffer sb = new StringBuffer(); ("UPDATE "+ rCase() +" SET "); for(
sb = LastChar(sb);
return ("%s where %s='%s'", ng(), idColumn, idValue); }}
2023年8月3日发(作者:)
JAVA通过Map拼接SQL语句(InsertUpdate语句)package ;import ;import ls;import Utils;public class SQLUtils {
/** * 通过Map拼接Insert SQL语句 *
* @param tableName * @param dataMap * @return */ public static String genSqlInsert(String tableName, Map
//⽣成INSERT INTO table(field1,field2) 部分 StringBuffer sbField = new StringBuffer(); //⽣成VALUES('value1','value2') 部分 StringBuffer sbValue = new StringBuffer();
("INSERT INTO " + rCase() + "("); for(
("`" + mapKey + "`,"); ("'" + mapValue + "',"); }
sbField = LastChar(sbField); sbValue = LastChar(sbValue); return ng() + ") VALUES(" + ng() + ")"; }
/** * 通过Map拼接Update SQL语句 *
* @param tableName * @param operation * @param dataMap * @return */ public static String genSqlUpdate(String tableName, Map
String idColumn = (); String idValue = (idColumn);
StringBuffer sb = new StringBuffer(); ("UPDATE "+ rCase() +" SET "); for(
sb = LastChar(sb);
return ("%s where %s='%s'", ng(), idColumn, idValue); }}
发布评论