Guest User

Untitled

a guest
Dec 11th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. package data;
  2.  
  3. import java.util.*;
  4. import javax.sql.*;
  5. import org.springframework.jdbc.core.JdbcTemplate;
  6.  
  7. public class GrupoGateway extends TableGateway {
  8.  
  9. private final static findWithProfesorId =
  10. "SELECT * "+
  11. "FROM grupo "+
  12. "WHERE id_profesor = ?";
  13.  
  14. public Map<String, Object> findWithProfesor(int id_profesor) {
  15. List profs = jdbcTemplate.queryForList(findWithProfesorId,id_profesor);
  16. return (Map<String, Object>)profs.get(0);
  17. }
  18.  
  19. private final static String findStatement =
  20. "SELECT * "+
  21. "FROM grupo "+
  22. "WHERE id = ?";
  23.  
  24. public Map<String, Object> find(String id) {
  25. List profs = jdbcTemplate.queryForList(findStatement,id);
  26. return (Map<String, Object>)profs.get(0);
  27. }
  28.  
  29. private final static String findAllStatement =
  30. "SELECT * "+
  31. "FROM grupo ";
  32.  
  33. public List<Map<String, Object>> findAll() {
  34. return jdbcTemplate.queryForList(findAllStatement);
  35. }
  36.  
  37. private static final String insertStatement =
  38. "INSERT INTO grupo "+
  39. "VALUES (?,?,?,?,?,?,?)";
  40.  
  41. public int insert(int numero,String sigla,String nombre,String horario,String aula,int id_profesor) {
  42. Random generator = new Random();
  43. int id = generator.nextInt();
  44. jdbcTemplate.update(insertStatement,
  45. id,numero,sigla,nombre,horario,aula,id_profesor);
  46. return id;
  47. }
  48.  
  49. private static final String updateStatement =
  50. "UPDATE grupo "+
  51. "SET numero = ?, sigla = ?, nombre = ?, "+
  52. "horario = ?, aula = ?, id_profesor = ? WHERE id = ?";
  53.  
  54. public void update(int id,int numero,String sigla,String nombre,String horario,String aula,String id_profesor) {
  55. jdbcTemplate.update(updateStatement,
  56. numero,sigla,nombre,horario,aula,id_profesor,id);
  57. }
  58.  
  59. private static final String deleteStatement =
  60. "DELETE FROM grupo "+
  61. "WHERE id = ?";
  62.  
  63. public void delete(int id) {
  64. jdbcTemplate.update(deleteStatement,id);
  65. }
  66.  
  67.  
  68. }
Add Comment
Please, Sign In to add comment