title: Spring MVC 4 + JSP + JDBC
body: <p>I'm using Spring MVC 4, JSP and MySQL to display data in a simple request.</p>
  
  <ul>
  <li><p><strong>Database Name&nbsp;:</strong> contactdb<br />
  <strong>Table Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</strong> contact
  <img src="https://i.stack.imgur.com/dxve6.png" alt="enter image description here"></p></li>
  <li><p>Records<br />
  <img src="https://i.stack.imgur.com/pnKPg.png" alt="enter image description here"></p></li>
  <li><p>My Folder Structure<br />
  <img src="https://i.stack.imgur.com/b4Qs0.png" alt="enter image description here"></p></li>
  <li><p>I have added the following dependencies in my pom.xml file:<br />
  ---> mysql-connector-java-5.1.30<br />
  ---> spring-jdbc-4.1.6<br /></p></li>
  <li><p><strong>com.rh.model/Contact.java</strong></p>
  
  <pre><code>public class Contact {
      private int id;
      private String name;
      private String email;
      private String address;
      private String telephone;
  
      //constructors
      //getters and setters
  }
  </code></pre></li>
  <li><p><strong>com.rh.dao/ContactDAO.java</strong><br /></p>
  
  <pre><code>public interface ContactDAO {
      public List&lt;Contact&gt; getAll();
  }
  </code></pre></li>
  <li><p><strong>com.rh.dao/ContactDAOImpl.java</strong><br /></p>
  
  <pre><code>public class ContactDAOImpl implements ContactDAO{
      private DataSource dataSource;
  
      public void setDataSource(DataSource dataSource) {
          this.dataSource = dataSource;
      }
  
      public List&lt;Contact&gt; getAll() {
          String sqlSelect = "SELECT * FROM contact";
          List&lt;Contact&gt; contactList = new ArrayList&lt;Contact&gt;();
          Connection conn = null;
          PreparedStatement ps = null;
          ResultSet rs = null;
  
          try{
              conn = dataSource.getConnection();
              ps = conn.prepareStatement(sqlSelect);
              rs = ps.executeQuery();
  
              while(rs.next()){
                  Contact contact = new Contact();
                  contact.setId(rs.getInt("contact_id"));
                  contact.setName(rs.getString("name"));
                  contact.setEmail(rs.getString("email"));
                  contact.setAddress(rs.getString("address"));
                  contact.setTelephone(rs.getString("telephone"));
                  contactList.add(contact);
              }
              rs.close();
              ps.close();
              conn.close();
         }catch(SQLException e){
              e.printStackTrace();
         }
      return contactList;
  }
  </code></pre></li>
  <li><p><strong>com.rh.config/Spring.xml</strong><br /></p>
  
  <pre><code>&lt;bean id="contactDAO" class="com.rh.dao.ContactDAOImpl"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/contactdb" /&gt;
      &lt;property name="username" value="root" /&gt;
      &lt;property name="password" value="" /&gt;
  &lt;/bean&gt;
  </code></pre></li>
  <li><p><strong>com.rh.controller/Test1Controller.java</strong><br /></p>
  
  <pre><code>@Controller
  public class Test1Controller {
  
  ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("com.rh.config/Spring.xml");
  
  ContactDAO contactDAO = ctx.getBean("contactDAO", ContactDAO.class);
  
  @RequestMapping(value="/")
  public ModelAndView listContact(ModelAndView model) throws IOException{
      List&lt;Contact&gt; listContract = contactDAO.getAll();
      model.addObject("listContact", listContract);
      return model;
  }
  </code></pre>
  
  <p>}</p></li>
  <li><p><strong>index.jsp</strong></p>
  
  <pre><code>...
  &lt;c:forEach var="contact" items="${listContact}" varStatus="status"&gt;
      &lt;tr&gt;
          &lt;td&gt;${status.index + 1}&lt;/td&gt;
          &lt;td&gt;${contact.name}&lt;/td&gt;
          &lt;td&gt;${contact.email}&lt;/td&gt;
          &lt;td&gt;${contact.address}&lt;/td&gt;
          &lt;td&gt;${contact.telephone}&lt;/td&gt;      
      &lt;/tr&gt;
  &lt;/c:forEach&gt;   
  </code></pre></li>
  <li><p>However, from above code, I can't get the database value. 
    <img src="https://i.stack.imgur.com/y3Ld6.png" alt="enter image description here"></p></li>
  <li><p>Which part am I writing wrong? </p></li>
  </ul>