Reputation: 867
Working with Spring, PostgreSQL and JDBC. Database is set up, and I am successfully using JDBC to pull data from the database. When using a form to make a POST
, however, the change doesn't go through. In debug mode, the correct attributes are present on the model, so I'm confident the error is in the database connection.
The form:
<form action="update-user" method="POST">
<ul class="form-flex-outer">
<li>
<label for="username">Username:</label>
<input type="text" name="username" value="${ currentUser.username }" />
</li>
<li>
<label for="password">Password:</label>
<input type="text" name="password" value="${ currentUser.password }" />
</li>
<li>
<label for="email">Email:</label>
<input type="text" name="email" value="${ currentUser.email }" />
</li>
<li>
<input type="submit" value="Submit changes" />
<input type="hidden" value="${ currentUser.userId }" />
</li>
</ul>
</form>
The controller:
@RequestMapping(path="/update-user", method=RequestMethod.POST)
public String submitUpdatedUserInformation(User user) {
userDAO.updateUserInformation(user);
return "redirect:/user-home";
}
The DAO method:
@Override
public void updateUserInformation(User user) {
String sqlQuery = "UPDATE users " +
"SET username = ?, " +
"password = ?, " +
"email = ?, " +
"updated_at = NOW() " +
"WHERE user_id = ?";
jdbcTemplate.update(sqlQuery, user.getUsername(), user.getPassword(), user.getEmail(), user.getUserId());
}
I understand there are configurations in the springmvc-servelet.xml
file concerning transactions, but I have worked with JDBC in the past without trouble.
User creation from DB init:
CREATE USER app_owner WITH PASSWORD 'app_owner1';
GRANT ALL
ON ALL TABLES IN SCHEMA public
TO app_owner;
GRANT ALL
ON ALL SEQUENCES IN SCHEMA public
TO app_owner;
Upvotes: 1
Views: 296
Reputation: 53754
Shouldn't
<input type="hidden" value="${ currentUser.userId } }" />
be
<input type="hidden" value="${ currentUser.userId }" name="userid" />
Upvotes: 1