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 Spring.Repaso02; import java.sql.Types; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; /** * * @author stdeceiver */ public class ClienteDAO implements ClienteDAOInterface { private JdbcTemplate jdbcTemplate; public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } @Override public boolean alta(Cliente c) { String inserQuery = "insert into TClientes (idCliente, Pass, Nombre, Apellidos, Telefono, Email) values (?, ?, ?, ?, ?, ?) "; Object[] params = new Object[] { c.getIdCliente(), c.getPassword(), c.getNombre(), c.getApellidos(), c.getTelefono(), c.getEmail() }; int[] types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }; jdbcTemplate.update(inserQuery, params, types); return true; } @Override public void modificacion(Cliente c) { String updateQuery = "update TClientes set Pass = ?, Nombre = ?, Apellidos = ?, Telefono = ?, Email = ? where IdCliente = ?"; Object[] params = new Object[] { c.getPassword(), c.getNombre(), c.getApellidos(), c.getTelefono(), c.getEmail(), c.getIdCliente() }; int[] types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }; jdbcTemplate.update(updateQuery, params, types); } @Override public Cliente consulta(String idCliente) { String selQuery = "select * from TClientes where idCliente = ?"; Cliente cliente = (Cliente) jdbcTemplate.queryForObject(selQuery, new Object[] { idCliente }, new int[] { Types.VARCHAR }, new BeanPropertyRowMapper(Cliente.class)); return cliente; } }