preparedStatement.executeUpdate语句不能执行

public boolean updateStaff(Staff staff) {
try {
if (connection == null) {
connection = ConnectionFactory.getConnection();
}
String sql = "update staff set staff_name=?,staff_auth=? where staff_id=?";
PreparedStatement preparedStatement = connection
.prepareStatement(sql);

        preparedStatement.setString(1, staff.getStaffName());
        preparedStatement.setString(2, staff.getStaffAuth());
        preparedStatement.setInt(3, staff.getStaffId());
        int row = preparedStatement.executeUpdate();
        if (row >= 1) {
            return true;
        } else {
            return false;
        }

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        ConnectionFactory.closeConnection(connection);
    }
}

调用:
Staff staff = new Staff();
staff.setStaffId(123);
staff.setStaffName("2");
staff.setStaffAuth("gh");
StaffDaoImpl staffDaoImpl = new StaffDaoImpl();
boolean i = staffDaoImpl.updateStaff(staff);
System.out.println(i);


不报错,参数都能正常传送,执行了preparedStatement.executeUpdate();返回0,不知道哪里有问题,各位大神帮帮忙啊

preparedstatement.executeUpdate()不需要返回值

该方法用于在此PreparedStatement对象中执行SQL语句,该语句必须是一个数据操作语句,如INSERT、UPDATE、DELETE,或者是无返回内容的SQL语句。

语法  executeUpdate() 

示例  下面的代码利用executeUpdate方法向数据库插入一条记录。
Connection conn = ……      //省略部分代码
String sql = "INSERT INTO users(username,pwd) VALUES ("lisi","123456")";
PreparedStatement ps = conn.prepareStatement(sql);
int i =ps.executeUpdate();     //执行
System.out.println(i);      //成功插入记录,打印1

这是我百度的,说明你代码没有问题,应该是逻辑有问题,你的sql应该有问题!!!更新有问题是不报错误的,这点要注意,
看看你的字段啥的都匹配好了么,插入都写对了吗

你这样把sql语句写死,把你数据库里的值,你直接写在代码里,看看能执行吗

String sql = "update staff set staff_name=?,staff_auth=? where staff_id=?";

问号直接写数据,下面不插入,直接执行,看看返回1么

2009年12月日语1级证书2009年12月日语二级证书2010-12日语N1级证书

碰到同样的问题。
而且非常明显:setString(1,"xxx") 和 setString(1,"xxx "),两者的差别是空格。有没有空格效果不一样,必须将参数填充空格到字段所需的长度。

但这样对编程是很麻烦的,我总不能老关注字段的长度。

各位大咖有没有解决办法?

我也遇到了同样的问题,请问这个解决了没?