public boolean updateMemberslnfo(MembersInfo membersInfo) throws SQLException{
StringBuffer sqlBuffer = new StringBuffer("UPDATE membersinfo SET ");
boolean check = true;
List<Object> params = new ArrayList<Object>();
if(membersInfo.getMname()!=null){
sqlBuffer.append(" mname=? ");
check = false;
params.add(membersInfo.getMname());
}
if(membersInfo.getMgender()!=null){
sqlBuffer =check?sqlBuffer.append(" mgender=? "):sqlBuffer.append(" ,mgender=? ");
check = false;
params.add(membersInfo.getMgender());
}
if(membersInfo.getMage()!=null){
sqlBuffer = check?sqlBuffer.append(" mage=? "):sqlBuffer.append(" ,mage=? ");
check = false;
params.add(membersInfo.getMage());
}
if(membersInfo.getMaddress()!=null){
sqlBuffer = check?sqlBuffer.append(" maddress=? "):sqlBuffer.append(" ,maddress=? ");
check = false;
params.add(membersInfo.getMaddress());
}
if(membersInfo.getMemall()!=null){
sqlBuffer = check?sqlBuffer.append(" memall=? "):sqlBuffer.append(" ,memall=? ");
check = false;
params.add(membersInfo.getMemall());
}
sqlBuffer.append(" where `mid`=?");
params.add(membersInfo.getMid());
boolean pd = executeUpdate(sqlBuffer.toString(),params)>0?true:false;
return pd;
}
进入此方法后params变成 [[洪波, 男, 1, 北京市丰台区长辛店大厦105室, mnbo@gand.com, 4]] 多 了 一 对 方 括 号
由于是Object数组形式 而我们是List<>泛型集合要写成 boolean pd = executeUpdate(sqlBuffer.toString(),params.toArray())>0?true:false;
StringBuffer sqlBuffer = new StringBuffer("UPDATE membersinfo SET ");
boolean check = true;
List<Object> params = new ArrayList<Object>();
if(membersInfo.getMname()!=null){
sqlBuffer.append(" mname=? ");
check = false;
params.add(membersInfo.getMname());
}
if(membersInfo.getMgender()!=null){
sqlBuffer =check?sqlBuffer.append(" mgender=? "):sqlBuffer.append(" ,mgender=? ");
check = false;
params.add(membersInfo.getMgender());
}
if(membersInfo.getMage()!=null){
sqlBuffer = check?sqlBuffer.append(" mage=? "):sqlBuffer.append(" ,mage=? ");
check = false;
params.add(membersInfo.getMage());
}
if(membersInfo.getMaddress()!=null){
sqlBuffer = check?sqlBuffer.append(" maddress=? "):sqlBuffer.append(" ,maddress=? ");
check = false;
params.add(membersInfo.getMaddress());
}
if(membersInfo.getMemall()!=null){
sqlBuffer = check?sqlBuffer.append(" memall=? "):sqlBuffer.append(" ,memall=? ");
check = false;
params.add(membersInfo.getMemall());
}
sqlBuffer.append(" where `mid`=?");
params.add(membersInfo.getMid());
boolean pd = executeUpdate(sqlBuffer.toString(),params)>0?true:false;
return pd;
}
进入此方法后params变成 [[洪波, 男, 1, 北京市丰台区长辛店大厦105室, mnbo@gand.com, 4]] 多 了 一 对 方 括 号
由于是Object数组形式 而我们是List<>泛型集合要写成 boolean pd = executeUpdate(sqlBuffer.toString(),params.toArray())>0?true:false;