一个还不错的SQL封装
public String zhpk_sql_2(String BA_ID,BGBAActionForm form)
StringBuffer sb = new StringBuffer("Update NTLJ_ZHPK a set ");
sb = sb.append("ZT='9'");
sb = sb.append(isNullNotUpdate("Name",form.getB_name()));
sb = sb.append(isNullNotUpdate("lxdh",form.getB_lxdh()));
sb = sb.append(isNullNotUpdate("zsdz",form.getB_zsdz()));
sb = sb.append(isNullNotUpdate("zzdz",form.getB_zzdz()));
sb = sb.append(isNullNotUpdate("Yzbm1",form.getB_yzbm1()));
sb = sb.append(isNullNotUpdate("yzbm2",form.getB_yzbm2()));
sb = sb.append(isNullNotUpdate("sfzmc",form.getB_sfzmc()));
sb = sb.append(isNullNotUpdate("sfzhm",form.getB_sfzhm()));
sb = sb.append(isNullNotUpdate("jzzmc",form.getB_jzzmc()));
sb = sb.append(isNullNotUpdate("jzzhm",form.getB_jzzhm()));
sb = sb.append(" where A.ID=(select ZID from Ntlj_Bgbab b where b.id = '"+BA_ID+"')");
return sb.toString();
}
public String isNullNotUpdate(String field,String value)
{
if(value== null || value.equals(""))
{
return "";
}
else
{
return ("," + field + "='" + value + "'");
}
}