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.magrocode.bm.service.dao.jdbc; import com.magrocode.bm.service.dao.SmtpConfigDao; import com.magrocode.bm.service.to.SmtpConfigTo; import java.sql.ResultSet; import java.sql.SQLException; import javax.sql.DataSource; 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.jdbc.core.RowMapperResultSetExtractor; import org.springframework.stereotype.Repository; /** * * @author mespinoza */ @Repository public class SmtpConfigDaoImpl implements SmtpConfigDao { private JdbcTemplate jdbcTemplate; public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } @Override public SmtpConfigTo[] getAll() { String sql = "SELECT * FROM SMTP_CONFIG;"; return (SmtpConfigTo[]) jdbcTemplate.query(sql, new RowMapper<SmtpConfigTo>() { @Override public SmtpConfigTo mapRow(ResultSet rs, int i) throws SQLException { SmtpConfigTo c = new SmtpConfigTo(); c.setId(rs.getInt("SMTP_CONFIG_ID")); c.setCompanya_id(rs.getInt("COMPANYA_ID")); c.setHost(rs.getString("SMTP_HOST")); c.setPort(rs.getInt("SMTP_PORT")); c.setAuth(rs.getBoolean("SMTP_AUTH")); c.setEmail(rs.getString("SMTP_EMAIL")); c.setUsername(rs.getString("SMTP_USERNAME")); c.setPassword(rs.getString("SMTP_PASSWORD")); return c; } }).toArray(new SmtpConfigTo[] {}); } @Override public SmtpConfigTo getById(int id) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public SmtpConfigTo createOrUpdate(SmtpConfigTo smptConfig) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public SmtpConfigTo update(SmtpConfigTo smptConfig) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public SmtpConfigTo create(SmtpConfigTo smptConfig) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public boolean delete(SmtpConfigTo smptConfig) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }