I read lot of information about this in the internet and implemented the solutions but I'm still seeing this, can someone please give me some help?
Here is what I'm doing:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub Connection connection = DbUtil.getConnection(); try { UserBean user = new UserBean(); user.setUserName(request.getParameter("username")); user.setPassword(request.getParameter("password")); user = UserDAO.login(user); Statement statement = connection.createStatement(); ResultSet rs = statement .executeQuery("SELECT * FROM projects WHERE status IN ('Waiting docs','Testing','On hold')"); List<Project> projects = new ArrayList<Project>(); while (rs.next()) { Project project = new Project(); project.setProject(rs.getString("project")); project.setStatus(rs.getString("status")); project.setPoc(rs.getString("poc")); project.setDescription(rs.getString("description")); project.setDeploy_date(rs.getString("deploy_date")); project.setCurrent_status(rs.getString("current_status")); project.setNotes(rs.getString("notes")); project.setId(rs.getString("id")); projects.add(project); } if (user.isValid()) { HttpSession session = request.getSession(true); session.setAttribute("currentSessionUser", user); request.setAttribute("project", projects); RequestDispatcher disp = request.getRequestDispatcher("ListProjects.jsp"); disp.forward(request, response); } else { RequestDispatcher disp = request.getRequestDispatcher("invalidLogin.jsp"); disp.forward(request, response); // error page } } catch (Throwable theException) { System.out.println(theException); } } My DbUtil:
package util; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; public class DbUtil { private static Connection connection = null; public static Connection getConnection() { if (connection != null) return connection; else { try { Properties prop = new Properties(); InputStream inputStream = DbUtil.class.getClassLoader() .getResourceAsStream("/db.properties"); prop.load(inputStream); String driver = prop.getProperty("driver"); String url = prop.getProperty("url"); String user = prop.getProperty("user"); String password = prop.getProperty("password"); Class.forName(driver); connection = DriverManager.getConnection(url, user, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return connection; } } } My db.properties have the autoconnect:
url=jdbc:mysql://localhost:3306/wsidb?autoReconnect=true
DbUtilclass is a really bad idea, you are sharing a single connection for all requests, leading to all kinds of nice concurrency problems. Use a connection pool instead.