JosepRivaille

BD - REPÀS: Qüestionari de repàs JDBC

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