I have two tables the first one is for "course" and the other is for "exam":
I want select exams which are matched to the code, of course, get by entering its name (nomCours)
here is my code :
try {
String select1 = "select code from cours where nomCours=?";
st2 = con.prepareStatement(select1);
st2.setString(1, nom);
rs2 = st2.executeQuery();
System.out.println(rs2.getInt("code"));
String select = "SELECT matricule FROM examen where code=?";
st = con.prepareStatement(select);
st.setInt(1, rs2.getInt("code"));
rs = st.executeQuery();
while (rs.next()) {
System.out.print(rs.getInt("matricule")+" ");
}
} catch (SQLException ex) {
System.err.print(ex);
}
this doesn't work, and it gives me this error :
java.sql.SQLException: Before start of result set