Hello everyone,
I dont know if im placing this in a good place.
I have a problem with my application. Its a simple application with connecting to database, retriving info and populating table.
I changed the apache tomcats context.xml to looks like this:

<Resource name="jdbc/test" auth="Container" type="javax.sql.DataSource"

maxActive="100" maxIdle="30" maxWait="10000"

username="root" password="MY_PASSWORD" driverClassName="com.mysql.jdbc.Driver"


****My jsp look like this: ****

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="java.util.*" %>
<%@ page import="business.Module" %>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<table border=1 bgcolor="lightgrey">
<tr> <th>ID</th><th>Code</th><th>Description</th><th>Lecturer</th>
<c:forEach var="module" items="${sessionScope.modules}">
      <td><c:out value="${module.id}" /></td>
      <td><c:out value="${module.code}" /></td>
      <td><c:out value="${module.description}" /></td>   
      <td><c:out value="${module.lecturer}" /></td>      
<form action="TestConnectionServlet" method="post">
        <input type="hidden" name="action" value="populate" />
        <input type="submit" value="populate table" />



After i run this i get the errors:

SEVERE: Servlet.service() for servlet [servlet.TestConnectionServlet] in context with path [/Database_Connection_Pooling_-_Exercise1] threw exception
at dao.ModuleDao.getAllModules(ModuleDao.java:28)
at servlet.TestConnectionServlet.doPost(TestConnectionServlet.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Im using the dao class, moduleDao and testConnectionServlet.

The code that error refers to

public class ModuleDao extends Dao {

public List<Module> getAllModules() throws DaoException {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    List<Module> modules = new ArrayList<Module>();

    try {
        //Get connection object using the methods in the super class (Dao.java)...
        con = this.getConnection();

        String query = "SELECT * FROM module";
        ps = con.prepareStatement(query);            <<<<<<<<<<-------- this is line 28

        //Using a PreparedStatement to execute SQL...
        rs = ps.executeQuery();
        while (rs.next()) {
            int id = rs.getInt("id");
            String code = rs.getString("code");
            String description = rs.getString("description");
            String lecturer = rs.getString("lecturer");

            Module m = new Module(id,code,description,lecturer);
    } catch (SQLException e) {
        throw new DaoException("getAllModules()" + e.getMessage());
    } finally {
        try {
            if (rs != null) {
            if (ps != null) {
            if (con != null) {
        } catch (SQLException e) {
            throw new DaoException(e.getMessage());

    return modules;

And TestConnectionServlet:

 * Servlet implementation class TestConnectionServlet
public class TestConnectionServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

 * Default constructor. 
public TestConnectionServlet() {
    // TODO Auto-generated constructor stub

 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if ( request.getParameter("action").equalsIgnoreCase("populate") ){
        String forwardToJsp = "";
        HttpSession session = request.getSession();
        ModuleDao mDao = new ModuleDao();

            List<Module> modules = new ArrayList<Module>();
            try {
                modules = mDao.getAllModules();     <<<---- this is line 53
            } catch (DaoException e) {

            session.setAttribute("modules", modules);
            forwardToJsp = "/TestConnection.jsp";   

        forwardToPage(request, response, forwardToJsp);

Im struggling with this whole day now and cant get it working. Any ideas what might be wrong?

Edited by peter_budo: moving to JSP section

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.