Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Imports de la classe */
- import java.sql.*;
- /* Capa de Control de Dades */
- class CtrlDadesPublic extends CtrlDadesPrivat {
- public ConjuntTuples consulta(Connection c, Tuple params) throws BDException {
- try {
- ConjuntTuples ct = new ConjuntTuples();
- ResultSet rs;
- Statement s = c.createStatement();
- rs = s.executeQuery("select count(*)"+
- " from assignacions" +
- " where dni = params.consulta(1);");
- rs.next();
- int nombreass = rs.getInt(1);
- if (nombreass >= 5) {
- throw new BDException(14);
- }
- s.executeUpdate("update assignacions set instantfi = '" +Integer.parseInt(params.consulta(4))+ "' - 1 where instantfi is NULL;");
- s.executeUpdate("insert into assignacions values ('" +params.consulta(1)+ "', '" +params.consulta(2)+ "', '" +params.consulta(3)+ "', '" +params.consulta(4)+ "');");
- Tuple t = new Tuple();
- t.afegir(Integer.toString(nombreass));
- ct.afegir(t);
- return ct;
- }
- catch(SQLException se) {
- //System.out.println(se.getMessage())
- if (se.getSQLState().equals("23503"))
- throw new BDException(12);
- if (se.getSQLState().equals("23505"))
- throw new BDException(13);
- throw new BDException(15); //error intern
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement