Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. /* Imports de la classe */
  2. import java.sql.*;
  3.  
  4.  
  5. /* Capa de Control de Dades */
  6. class CtrlDadesPublic extends CtrlDadesPrivat {
  7.    
  8.     public ConjuntTuples consulta(Connection c, Tuple params) throws BDException {
  9.         try {
  10.         ConjuntTuples ct = new ConjuntTuples();
  11.         String modul = params.consulta(1);
  12.         String superficie = params.consulta(2);
  13.         Statement stat = c.createStatement();
  14.         int numModificats = stat.executeUpdate("delete *  from despatxos d where d.modul = '"+ modul + "'"
  15.                                                         + "and d.superficie < '" + superficie +"'");
  16.         if (numModificats == 0) throw new BDException(12);
  17.        
  18.         PreparedStatement ps = c.prepareStatement("select sum(d.superficie) as Sup "+
  19.                 "from despatxos");
  20.         ResultSet res = null;
  21.         res = ps.executeQuery();
  22.         Tuple fila = new Tuple();
  23.         fila.afegir(res.getString(1));
  24.         ct.afegir(fila);
  25.         ResultSet res1 = null;
  26.         Statement s = c.createStatement();
  27.         res1 = s.executeQuery("select count(*), a.dni "
  28.                 + "from assignacions a"
  29.                 + "where a.instantFi NOT NULL"
  30.                 + "group by a.dni");
  31.         while (res1.next()) {
  32.             Tuple fila1 = new Tuple();
  33.             fila1.afegir(res1.getString(1));
  34.             fila1.afegir(res1.getString(2));
  35.             ct.afegir(fila1);
  36.         }
  37.         return ct;
  38.         }
  39.         catch(SQLException se) {
  40.             if (se.getSQLState().equals("23503")) {
  41.                 throw new BDException(13);
  42.             }else{
  43.                 throw new BDException(14);
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement