Advertisement
Guest User

Untitled

a guest
May 27th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 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. try {
  9. ConjuntTuples ct = new ConjuntTuples();
  10.  
  11. String modul = params.consulta(1);
  12. String superficie = params.consulta(2);
  13.  
  14. Statement s = c.createStatement();
  15. int ret = s.executeUpdate ("delete from despatxos "+
  16. "where modul = '" +modul+ "' and superficie < " +superficie+ ";");
  17. if (ret == 0) throw new BDException(12);
  18.  
  19. ResultSet rs;
  20. rs = s.executeQuery ("select count(*), sum(superficie) from despatxos;");
  21.  
  22. Tuple fila = new Tuple();
  23. rs.next();
  24. if (rs.getInt(1) == 0) fila.afegir("NO");
  25. else fila.afegir(rs.getString(2));
  26. ct.afegir(fila);
  27.  
  28. rs = s.executeQuery ("select nomprof, count(*) "+
  29. "from assignacions natural inner join professors "+
  30. "where instantfi is not null group by dni, nomprof;");
  31. while (rs.next()) {
  32. fila = new Tuple();
  33. fila.afegir(rs.getString(1));
  34. fila.afegir(rs.getString(2));
  35. ct.afegir(fila);
  36. }
  37.  
  38. return ct;
  39. }
  40. catch (SQLException se) {
  41. /*System.out.println ("El getSQLState es: " + se.getSQLState());
  42. System.out.println ();
  43. System.out.println ("El getMessage es: " + se.getMessage());*/
  44.  
  45. if (se.getSQLState().equals("23503")) throw new BDException(13);
  46. else throw new BDException(14);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement