日期:2014-05-20  浏览次数:20707 次

JAVA查询某个字段为空更新
JAVA查询某个字段为空,返回个true或false,然后更新这个字段,怎么简化下,能不能放到一个SQL语句里
Java code

string str=null;
String sql = ("select salesmanname from order where orderID = '"+033+"'");    
sta.executeQuery(sql)
try {
    while(rs.next()) {
        str = rs.getString(1);    
    }
    if(str != null) {
        isname = true;    //如果为空 返回true,反之返回false
        return;
    }
    else {
        isname = false
        Strin sql = ("update order set salesmanname ='"+NewName+"' where orderID = '"+033+"'");            
        sta.executeQuery(sql);
    }
} catch (Exception e) {
    e.printStackTrace();
} 



------解决方案--------------------
update 。。。。 where id=‘’ and salesmanname =''
------解决方案--------------------
update table set xx=? where id="22" and (salesmanname is null or salesmanname = '')