My query is as follows, I have 3 related tables (students, tutors, kinship) and a jtable
which shows me the data from a database MYSQL
, but I want to right click and give to the option "Data Tutor" which I have done with a jmenuitem
, another window with the data of the tutor opens this is my code:
try {
String sql = "SELECT p.DescParentezco,t.Apellidos,t.Nombres,t.Telefono,t.Dirección,t.Correo\n"
+ "FROM parentezco p, alumnos a, tutores t\n"
+ "WHERE t.IdParentezco = p.IdParentezco\n"
+ "and t.IdAlumno = a.IdAlumno";
Statement st = cn.createStatement();
ResultSet ConsultaTutor = st.executeQuery(sql);
while (ConsultaTutor.next()) {
DatosDelTutor.txtparentezcotutor.setText((String) ConsultaTutor.getString(1));
//DatosDelTutor.txtparentezcotutor.setText(ConsultaTutor.getString(1));
DatosDelTutor.txtapellidotutor.setText(ConsultaTutor.getString(2));
DatosDelTutor.txtnombretutor.setText(ConsultaTutor.getString(3));
DatosDelTutor.txtteletutor.setText(ConsultaTutor.getString(4));
DatosDelTutor.txtdirectutor.setText(ConsultaTutor.getString(5));
DatosDelTutor.txtcorrtutor.setText(ConsultaTutor.getString(6));
}
} catch (Exception e) {
}
I think my error is to use the next()
method in the RS class, since this method shows you the last data in the database. Can anyone help me?