Hi..., i have a problem. if anyone can please give me some suggestion then i could able to proceed further. My problem is that i need to show database values in JTable. i have two database table and i query to display data in a JTable.
I am just sending a part of my code. I am using MultipleColumnHeader in JTable. When i try to run then it gives me runtime error saying---
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 >= 0
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableColumnModel.getColumn(Unknown Source)
at com.ws.ui.CompHoursPanel.getCompareDataPanel2(CompHoursPanel.java:207)
at com.ws.ui.CompHoursPanel.compHoursPanel(CompHoursPanel.java:254)
Please give me some suggestion. Any help from you will highly be appreciated. Thanks.
private JPanel getCompareDataPanel2(){
JPanel panel=new JPanel();
DaoWeatherImpl dao=new DaoWeatherImpl();
//Result set is taken from another class called DaoWeatherImpl
//and there is a method called getCompareDataStatus()
ResultSet rs=dao.getCompareDataStatus();
DefaultTableModel model=new DefaultTableModel();
String[] a = {"Time","O","F","O","F","O","F","O","F"};
try
{
while (rs.next())
{
a[0]=rs.getString("TimeStamp").substring(11,16);
a[1]=rs.getString("Temperature");
a[2]=rs.getString("Temperature");
a[3]=rs.getString("Rainfall");
a[4]=rs.getString("Rainfall");
a[5]=rs.getString("Wind");
a[6]=rs.getString("Wind");
a[7]=rs.getString("Rh");
a[8]=rs.getString("Rh");
model.addRow(a);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null, "Exception : "+e, "Error", JOptionPane.ERROR_MESSAGE);
}
JTable jtab=new JTable(model){
protected JTableHeader createDefaultTableHeader() {
return new GroupableTableHeader(columnModel);
}
};
TableColumnModel cm = jtab.getColumnModel();
ColumnGroup g_temp = new ColumnGroup(null,"Temperature");
g_temp.add(cm.getColumn(1));
g_temp.add(cm.getColumn(2));
ColumnGroup g_rf = new ColumnGroup(null,"Rainfall");
g_rf.add(cm.getColumn(3));
g_rf.add(cm.getColumn(4));
ColumnGroup g_wind = new ColumnGroup(null,"Wind");
g_wind.add(cm.getColumn(5));
g_wind.add(cm.getColumn(6));
ColumnGroup g_rh = new ColumnGroup(null,"Rh");
g_rh.add(cm.getColumn(7));
g_rh.add(cm.getColumn(8));
GroupableTableHeader header = (GroupableTableHeader)jtab.getTableHeader();
header.addColumnGroup(g_temp);
header.addColumnGroup(g_rf);
header.addColumnGroup(g_wind);
header.addColumnGroup(g_rh);
JScrollPane scroll= new JScrollPane( jtab );
scroll.setBackground(Color.WHITE);
panel.add(scroll,BorderLayout.CENTER);
return panel;
}