Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@appplemac
Last active December 17, 2015 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appplemac/5599347 to your computer and use it in GitHub Desktop.
Save appplemac/5599347 to your computer and use it in GitHub Desktop.
JDBC stuff
/* 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