Skip to main content

Problem with JTable and ResultSet

1 reply [Last post]
dnix
Offline
Joined: 2012-08-18
Points: 0

Hello Everybody:

i´m new in this forum and this is my first thread, i hope you can help me, i have a problem with JTable and ResultSetScrollable, the question is that i have a JTable with AbstractTableModel, in the class AbstractTableModel, i override the three methods, getvalueat, getcolumnname....also i have a ComboBox, when i select a value of the ComboBox, the JTable shows the data associated with the ComboBox.

Well, the problem is that JTable only shows INTEGER data, but String not, i don´t know why this could be.

if someone knows anything about this, would be very grateful.

this is a part of the code:

**********This is the AbstractTableModel*****************************************
public class PersonalTableModel extends AbstractTableModel{
ResultSet rs;

public PersonalTableModel(ResultSet rs) {
this.rs=rs;

}

public Object getValueAt(int ri, int ci) {
Object ob=null;

try{

rs.absolute(ri+1);

ob=rs.getObject(ci+1);

}catch(Exception e){
e.printStackTrace();
}
return ob;

}

*************************************************************
****This is the ItemListener for the ComboBox*******************
public class ComboCambio implements ItemListener{
//Recogemos en un objeto tipo ventanaprincipal la ventana principal para acceder a los controles
VentanaPrincipal ventanaprincipal;

public ComboCambio(VentanaPrincipal ventana){
this.ventanaprincipal=ventana;
}
public void itemStateChanged(ItemEvent e) {
PersonalTableModel pt;
Sql sql=new Sql("BBDDChefDnix");

Grupo g=(Grupo)ventanaprincipal.combobox.getSelectedItem();

pt=new PersonalTableModel(sql.getResultSetScrollable(g.getGrupo()));

//Una vez tenemos el elemento del combobox actualizamos la tabla.

this.ventanaprincipal.tabla.setModel(pt);

}

}
***************************************************

If you need more code, please tell me and i paste it.

Thxxxxxxxxxxxxxxxxxxxx a lot!!!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
darrylburke
Offline
Joined: 2010-08-05
Points: 0