Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. /* Imports de la classe */
  2. import java.sql.*;
  3.  
  4. /* Capa de Control de Dades */
  5. class CtrlDadesPublic extends CtrlDadesPrivat {
  6.    
  7.     public ConjuntTuples consulta(Connection c, Tuple params) throws BDException {
  8.         ConjuntTuples ct = new ConjuntTuples();
  9.        
  10.         String modul = params.consulta(1);
  11.         String superficie = params.consulta(2);
  12.        
  13.         try {
  14.             Statement query = c.createStatement();
  15.             int numBorrad = query.executeUpdate("delete from despatxos "+
  16.                                                 "where modul = '" + modul +
  17.                                                 "' and superficie < '" + superficie + "';");
  18.             if(numBorrad == 0) throw new BDException(12);
  19.            
  20.             ResultSet rs = query.executeQuery("select sum(superficie) as sumSuperficies from despatxos");
  21.             rs.next();
  22.             int sum_sup = rs.getInt("sumSuperficies");
  23.             if(rs.wasNull()) {
  24.                 Tuple fila = new Tuple();
  25.                 fila.afegir("NO");
  26.                 ct.afegir(fila);
  27.             } else {
  28.                 Tuple fila = new Tuple();
  29.                 fila.afegir(Integer.toString(sum_sup));
  30.                 ct.afegir(fila);
  31.             }
  32.            
  33.             rs = query.executeQuery("select p.nomProf as nomProf, count(*) as assigFin " +
  34.                                     "from assignacions as a, professors as p " +
  35.                                     "where a.dni = p.dni and a.instantfi is not null " +
  36.                                     "group by p.dni;");
  37.  
  38.             while(rs.next()) {
  39.                 Tuple fila = new Tuple();
  40.                 fila.afegir(rs.getString("nomProf"));
  41.                 fila.afegir(Integer.toString(rs.getInt("assigFin")));
  42.                 ct.afegir(fila);
  43.             }
  44.            
  45.            
  46.         } catch (SQLException se) {
  47.             //System.out.println(se.getSQLState() +" "+ se.getMessage());
  48.             if (se.getSQLState().equals("23503")) throw new BDException(13);
  49.             else throw new BDException(14);
  50.         }
  51.        
  52.         return ct;
  53.     }
  54. }
  55.  
  56.  
  57.  
  58.  
  59. //System.out.println(se.getSQLState() +" "+ se.getMessage());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement