生成sql语句
public static String querySQL(Map<Object,Object> map,String tableName){
//判断是否为空
String sqlCommon=””;
if (map.isEmpty()||map.size()0) {
} else {
sqlCommon = “INSERT INTO “+tableName+” (”;
Set set = map.keySet();
Iterator iterable = set.iterator();
int index = 0;
String values=””;
while(iterable.hasNext()){
String key = (String)iterable.next();
Object value = map.get(key);
values+=”’”+value+”’”;
index++;
//仅有一个参数或是最后一个参数
if ( ( index1&&map.size()==1)||map.size()==index) {
sqlCommon += key+”) VALUES (“+values+”);”;
} else {
sqlCommon += key+”,”;
values+=”,”;
}
}
}
return sqlCommon;
}
map生成sql插入语句
版权声明:本文为qq_43003860原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。