Advertisement
Guest User

Untitled

a guest
May 27th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 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.         ResultSet rs;
  11.         Statement s = c.createStatement();
  12.         rs = s.executeQuery("select count(*)"+
  13.         " from assignacions" +
  14.         " where dni = params.consulta(1);");
  15.         rs.next();
  16.         int nombreass = rs.getInt(1);
  17.         if (nombreass >= 5) {
  18.             throw new BDException(14);
  19.         }
  20.         s.executeUpdate("update assignacions set instantfi = '" +Integer.parseInt(params.consulta(4))+ "' - 1 where instantfi is NULL;");
  21.  
  22.         s.executeUpdate("insert into assignacions values ('" +params.consulta(1)+ "', '" +params.consulta(2)+ "', '" +params.consulta(3)+ "', '" +params.consulta(4)+ "');");
  23.         Tuple t = new Tuple();
  24.         t.afegir(Integer.toString(nombreass));
  25.         ct.afegir(t);
  26.         return ct;
  27.     }
  28.     catch(SQLException se) {
  29.         //System.out.println(se.getMessage())
  30.         if (se.getSQLState().equals("23503"))
  31.             throw new BDException(12);
  32.         if (se.getSQLState().equals("23505"))
  33.             throw new BDException(13);
  34.         throw new BDException(15); //error intern
  35.     }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement