Reputation: 127
I created (my first) small spring 3 MVC application, but ran into an issue which is a little bit mysterious for me.
The application has a few forms to manipulate a database. I created one Controller Java class which maps all requests to java Methods (see code). After a few requests in the browser the web app crashes. The code for manipulating a database entry is called successfully but the reload of the page seem to fail.
Controller class:
@RequestMapping("/usermanager")
public String getUserInfo(Map<String, Object> map) throws ServletException {
try {
map.put("userInfo", userService.getUserInfo());
} catch (Exception e) {
throw new ServletException(e);
}
return "usermanager";
}
@RequestMapping("/updateUserInfo")
public String updateUserInfo(@ModelAttribute("userInfo") User user) throws NamingException, SQLException {
userService.storeUserInfo(user);
return "redirect:/service/usermanager";
}
The structure is really easy, the request usermanager is called to show the table data. The site shows a form where I can edit my data, submitting the form calls the updateUserInfo request. After a few times the request hangs at return "usermanager";.
Did someone have an explanation for this behavior, Or an idea?
Edit: BTW: There are no Exceptions or something else. The web app simply hangs.
Many thanks, Regards Sascha
Upvotes: 1
Views: 1234
Reputation: 127
i found the bug. Looked at the wrong place.
The error occurs indeed in the getUserInfo(). But it is a more general problem with my database connection method.
Everytime a do a database query, i called: connection = dataSource.getConnection();
That causes the leak.
It is better to check if there is already a connection :-D
if (connection == null || connection.isClosed()) {
connection = dataSource.getConnection();
}
BTW I use an embedded Derby Database which is accessed by the jdbcTemplate.
Sometimes we do not see the wood for the trees :-)
Thanks for your effort. Have a nice day Sascha
Upvotes: 2