在编写JDBC时,遇到执行 PreparedStatement.executeUpdate(); 没有返回值,
例如下面的代码:
/**
* sql
* 根据uids 更新 uname
*/
@Override
public boolean updateIdOfUserInfo(UserInfo userinfo) {
// TODO Auto-generated method stub
boolean flag=false;
Connection conn=null;
PreparedStatement psmt=null;
ResultSet rs=null;
try {
String sql="update userinfo set uname=? where uids=?";
conn=this.openConnections();
psmt=conn.prepareStatement(sql);
psmt.setString(1,userinfo.getUname());
psmt.setInt(2, userinfo.getUids());
int num=psmt.executeUpdate();//debug执行到这一步没有返回值,num还是0
if(num>0){
flag=true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.closeZiYuan(conn, psmt, rs);
}
return flag;
}
测试代码:
/**
* 更新