Advertisement
JosepRivaille

BD - Pràctica JDBC 1 - Segona Part

May 13th, 2016
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.sql.*;
  2. import java.io.*;
  3.  
  4. class CtrlDadesPublic extends CtrlDadesPrivat {
  5.     public ConjuntTuples consulta(Connection c, Tuple params) throws BDException {
  6.         try {
  7.             ConjuntTuples ct = new ConjuntTuples();
  8.             ResultSet rs = null;
  9.             PreparedStatement ps = c.prepareStatement("SELECT COUNT(*) FROM assignacions a WHERE a.dni = ?;");
  10.             int i = 1;
  11.             while (!(params.consulta(i).equals("-999"))) {
  12.                 ps.setString(1, params.consulta(i));
  13.                 rs = ps.executeQuery();
  14.                 rs.next();
  15.                 Tuple t = new Tuple();
  16.                 t.afegir(params.consulta(i));
  17.                 t.afegir(rs.getString(1));
  18.                 ct.afegir(t);
  19.                 i++;
  20.             }
  21.             return ct;
  22.         }
  23.         catch (SQLException se) {
  24.             throw new BDException(11);
  25.         }
  26.     }
  27. }
  28.  
  29. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement