这是代码:
@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.");
}
我假设我错过了一些简单的事情。很明显,我只是看不到。
答案 0 :(得分:2)
此查询不会更新任何内容 - 它只是将大量列设置为其现有值。如果你想将它们更新为其他东西,你最好以某种方式传递那些“别的”值。
答案 1 :(得分:0)
我注意到两件事,你可能想要getEmployeeID()
和Limit 1
之间的空格;另外,假设您未启用autoCommit,则需要致电Connection.commit()。最后,您应该关闭finally
块中的连接和语句对象。