Start New Discussion within our Web Development Community

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" "">

<%@ taglib uri="" 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="${}" /></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(
at servlet.TestConnectionServlet.doPost(
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(

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 (
        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 ( {
            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?

This question has already been answered. Start a new discussion instead.