我有一个基本的Update Where语句,该语句是完全正确的但不更新表

时间:2013-11-24 22:38:57

标签: java mysql

这是代码:

@Override public void update(){
    Statement stmt = null;
    String company = "";
    try {
        Connect conn = new Connect();
        stmt = conn.makeStatement();
        // This creates the SQL statement to update an existing student.
        System.out.println("Update employee"
                         + " Set employeeID = employeeID,"
                         + " firstName = firstName,"
                         + " lastName = lastName,"
                         + " paRating = paRating,"
                         + " status = status,"
                         + " manager = managerr,"
                         + " level = level,"
                         + " company = company"
                         + " WHERE employeeID = " + get EmployeeID() 
                         + "Limit 1");

        stmt.execute("Update employee"
                         + " Set employeeID = employeeID,"
                         + " firstName = firstName,"
                         + " lastName = lastName,"
                         + " paRating = paRating,"
                         + " status = status,"
                         + " manager = managerr,"
                         + " level = level,"
                         + " company = company"
                         + " WHERE employeeID = " + get EmployeeID() 
                         + "Limit 1");

        stmt.close();
        conn.close();
    } catch (SQLException e) {
        e.printStackTrace();
        System.err.println("Unable to update employee in the database.");
    } finally {
    }
    System.out.println("Employee successfully updated to the database.");
 }

我假设我错过了一些简单的事情。很明显,我只是看不到。

2 个答案:

答案 0 :(得分:2)

此查询不会更新任何内容 - 它只是将大量列设置为其现有值。如果你想将它们更新为其他东西,你最好以某种方式传递那些“别的”值。

答案 1 :(得分:0)

我注意到两件事,你可能想要getEmployeeID()Limit 1之间的空格;另外,假设您未启用autoCommit,则需要致电Connection.commit()。最后,您应该关闭finally块中的连接和语句对象。