Aiuto con la tesina (java+database)

Pubblicità

NicoZ96

Utente Attivo
Messaggi
1,079
Reazioni
128
Punteggio
75
public void caricaTabella() throws FileNotFoundException, IOException, SQLException {
try {
int i = 0, j = 0;
Class.forName("com.mysql.jdbc.Driver");
Connection cnt = DriverManager.getConnection("jdbc:mysql://localhost", "root", "");
cnt.setCatalog("tesina"); //nome del database
Statement st = cnt.createStatement();
ResultSet rt= st.executeQuery("SELECT Nome, Cognome, ID, Appunti FROM studente ORDER BY Cognome, Nome;");
for(i=0 ;rt.next();i++){
setValueAt(rt.getObject("Cognome", String.class),i, 1);
setValueAt(rt.getObject("Nome", String.class),i, 2);
setValueAt(rt.getObject("Appunti", String.class),i, 3);
Statement stvoti = cnt.createStatement();
ResultSet rtvoti= stvoti.executeQuery("SELECT Valore FROM studente, voto WHERE voto.ID_Studente = "+rt.getObject("ID", Integer.class)+";");
System.out.println("valore ID studente" + rt.getObject("ID", Integer.class));
for(j=4 ;rtvoti.next();j++){
setValueAt(rtvoti.getObject("Valore", String.class),i, j);
System.out.println("valore voto nel for" + rtvoti.getObject("Valore", String.class));
}

rtvoti.close();
stvoti.close();
}
rt.close();
st.close();
cnt.close();
} catch (ClassNotFoundException ex) {
Logger.getLogger(MyTableModel.class.getName()).log(Level.SEVERE, null, ex);
}
}


Ho incollato il metodo che mi dà problemi. I system.out erano solo per controllare cosa producesse e appunto facendolo mi sono reso conto che il ciclo for in rosso, stampa n volte lo stesso voto quante il numero di studenti, ma non riesco a capirne il perchè. Qualche idea? (se servono altre parti di codice/vedere come è fatto il database chiedete pure)
 
Pubblicità
Pubblicità
Indietro
Top