//方法2:拼接sql语句进行插入操作
String insertFields = "";
String sql = "insert into "+ key_table_dest;
String insertValues = "";
for(Map<String, Object> map : srcDataList){
insertFields = StringUtils.join(map.keySet(), ",");
insertValues += "(‘"+StringUtils.join(map.values(), "‘,‘")+"‘),";
}
if(insertValues.length()>0){
insertValues = insertValues.substring(0, insertValues.length()-1);
}
sql += "("+insertFields+") values " + insertValues;
Session session = null;
try
{
session = getXXXHibernateTemplate().getSessionFactory().openSession();
session.createSQLQuery(sql).executeUpdate();
}
catch (Exception e)
{
// TODO: handle exception
}finally{
if(session!=null && session.isOpen()){
session.close();
}
}
}
}
}
}
时间: 2024-10-27 10:47:32