display data from a table in mysql using a jtable


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));


} 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?

asked by Vlado Santa Cruz Cabanillas 03.07.2017 в 17:57

1 answer


If you want to make sure everything comes out correctly you should use the print in console.


Once you have verified that everything goes now if you pass it to the JTable.

I will give you some advice, the JTable only grabs PRIMITIVE values so you must convert the COMPOSITE values of your database into PRIMITIVES, in this way they will be displayed. If you do not do it like this they will not show up.

answered by 03.07.2017 в 18:10