页面内数据查重
使用了 hashset不会有重复元素的这一特性:
把数据放入hashset中,如果有重复元素,hashset将只保存一个,那么其size相对之前将会变小;
ArrayList<String> detail = new ArrayList<String>();
for(int i =0; i <detailArray.size();i++ ) {
detail.add(detailArray.get(i)+detailArray2.get(i));
}
String message =null;
//页面内预算项目查重
boolean isRepeat = detail.size() != new HashSet<String>(detail).size();
提交数据和数据库内数据查重:
通过sql语句: if exists() select '' else select ''
相对于之前,不用把数据从数据库中取出来比对,只看返回结果就可以
private boolean getDBchongfu(ArrayList<String> detailArray,ArrayList<String> detailArray2,Map<String, Object> formPropert) {
String year = formPropert.get("year").toString();
String zt = formPropert.get("zt").toString();
RecordSetTrans rs = new RecordSetTrans();
for(int i =0;i<detailArray.size();i++) {
String sql ="if exists (select * from [ecology].[dbo].[uf_ysb] where year = '"
+ year + "' and " + "zt='" + zt + "' and " + "u8bmbm='"+detailArray.get(i)+"' and "+ "ysxmbm='"+detailArray2.get(i)+"'"
+ ") select '111' else select '000'";
log.info("sql=="+sql);
//如果存在返回111
//不存在返回000
try {
rs.executeQuery(sql);
while (rs.next()) {
String returnstr = rs.getString("");
log.info("returnstr=="+returnstr);
if(returnstr.equals("111")) {
return false;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return true;
}