Redvex
18-06-2008, 15:12
Sto facendo un programma in java/jsf/jsp utilizzando mysql come dbms; ora nel get di una variabile eseguo queste 3 query:
public String getNome_matr() {
sql ="SELECT MAX(id) FROM post";
ResultSet rs = sqlCommandBean.executeQuery(sql);
try{
rs.next();
this.id = rs.getInt("MAX(id)");
}catch (Exception e){}
sql="SELECT matr_dipendente FROM inserisce WHERE id_post='"+this.id+"'";
ResultSet rs1 = sqlCommandBean.executeQuery(sql);
try{
rs1.next();
matr_post = rs1.getInt("matr_dipendente");
}catch (Exception e){}
sql ="SELECT nome FROM dipendente WHERE matricola='"+matr_post+"'";
ResultSet rs2 = sqlCommandBean.executeQuery(sql);
try{
rs2.next();
nome_matr= rs2.getString("nome");
}catch(Exception e){}
return nome_matr;
}
Come posso concentrare queste 3 query per avere solo 1 resultset?
Avendo delle buone prestazioni magari
public String getNome_matr() {
sql ="SELECT MAX(id) FROM post";
ResultSet rs = sqlCommandBean.executeQuery(sql);
try{
rs.next();
this.id = rs.getInt("MAX(id)");
}catch (Exception e){}
sql="SELECT matr_dipendente FROM inserisce WHERE id_post='"+this.id+"'";
ResultSet rs1 = sqlCommandBean.executeQuery(sql);
try{
rs1.next();
matr_post = rs1.getInt("matr_dipendente");
}catch (Exception e){}
sql ="SELECT nome FROM dipendente WHERE matricola='"+matr_post+"'";
ResultSet rs2 = sqlCommandBean.executeQuery(sql);
try{
rs2.next();
nome_matr= rs2.getString("nome");
}catch(Exception e){}
return nome_matr;
}
Come posso concentrare queste 3 query per avere solo 1 resultset?
Avendo delle buone prestazioni magari