Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.leapfrog.academyspring.dao.impl; import com.leapfrog.academyspring.constants.SQLConstants; import com.leapfrog.academyspring.dao.EnquiryDAO; import com.leapfrog.academyspring.entity.Enquiry; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.ResultSetExtractor; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Repository; /** * * @author Suman Heuju */ @Repository(value = "EnquiryDAO") public class EnquiryDAOImpl implements EnquiryDAO { @Autowired private JdbcTemplate jdbcTemplate; @Override public int insert(Enquiry e) { return jdbcTemplate.update(SQLConstants.ENQUIRY_INSERT, new Object[] { e.getFirstName(), e.getLastName(), e.getEmail(), e.getContactNo(), e.getMessage() }); } @Override public int update(Enquiry e) { return jdbcTemplate.update(SQLConstants.ENQUIRY_UPDATE, new Object[] { e.getId(), e.getLastName(), e.getLastName(), e.getEmail(), e.getContactNo(), e.getMessage() }); } @Override public int delete(int id) { return jdbcTemplate.update(SQLConstants.ENQUIRY_DELETE, new Object[] { id }); } @Override public List<Enquiry> getAll() { return jdbcTemplate.query(SQLConstants.ENQUIRY_GETALL, new RowMapper<Enquiry>() { @Override public Enquiry mapRow(ResultSet rs, int i) throws SQLException { Enquiry enq = new Enquiry(); enq.setId(rs.getInt("id")); enq.setFirstName(rs.getString("first_name")); enq.setLastName(rs.getString("last_name")); enq.setEmail(rs.getString("email")); enq.setContactNo(rs.getString("contact_no")); enq.setCourseId(rs.getInt("course_id")); enq.setMessage(rs.getString("message")); enq.setEnquiryDate(rs.getDate("enquiry_date")); enq.setIsRead(rs.getBoolean("is_read")); enq.setParentId(rs.getInt("parent_id")); return enq; } }); } @Override public Enquiry getById(int id) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }