JDBC stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Imports de la classe */ | |
import java.sql.*; | |
import java.io.*; | |
/* Capa de Control de Dades */ | |
class CtrlDadesPublic extends CtrlDadesPrivat { | |
public ConjuntTuples consulta(Connection c, Tuple params) throws BDException { | |
try { | |
ConjuntTuples ct = new ConjuntTuples(); | |
int i = 1; | |
String s = params.consulta(i); | |
PreparedStatement ps = c.prepareStatement("select count(*) from assignacions a, professors p " | |
+ "where a.dni = p.dni and p.dni = ?"); | |
while (!s.equals("-999")) { | |
ps.setString(1, s); | |
ResultSet rs = ps.executeQuery(); | |
if (!rs.isBeforeFirst()) throw new BDException(11); | |
Tuple t = new Tuple(); | |
while (rs.next()) { | |
t.afegir(s); | |
t.afegir(Integer.toString(rs.getInt(1))); | |
} | |
rs.close(); | |
ct.afegir(t); | |
++i; | |
s = params.consulta(i); | |
} | |
ps.close(); | |
return ct; | |
} | |
catch(SQLException e) { | |
System.out.println(e.getSQLState()); | |
System.out.println(e.getMessage()); | |
return new ConjuntTuples(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment