I have the following method, using Hibernate, that's driving me nuts. It's not updating my database correctly, and I cannot see what the problem. Can anyone help me with this?
public boolean changePassword(String username, String password) {
HttpServletRequest request = ServletActionContext.getRequest();
SessionFactory sessionFactory = (SessionFactory) request.getSession()
.getServletContext().getAttribute("sessionFactory");
Session session = sessionFactory.openSession();
try {
request = ServletActionContext.getRequest();
Query myQuery = session.createQuery("update Administrator "
+ "set password = " + password + " where username = "
+ username);
if (myQuery.executeUpdate() == 1) {
return true;
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return false;
}
Here is what I have in my console:
Hibernate: update login set password=password1 where username=frank
could not execute update query