Sunday, 11 August 2013

error when deleting a row from a JTABLE

error when deleting a row from a JTABLE

I have a JTable connected to a database and a Delete button here is my code
filling the JTABLE with data:
static class inventoryTableItems{
Object tempRow[];
public static DefaultTableModel itemTableModel;
inventoryTableItems() throws SQLException{
getItems();
}
public void getItems() throws SQLException{
try {
itemTableModel = new
DefaultTableModel(MainFramePanels.inventory_Panels.data,
MainFramePanels.inventory_Panels.Columns);
connectDB();
rows = stmtUpd.executeQuery("select c.*, q.Qty from
catalogue=c inner join Quantity=q on c.SKU = q.SKU");
while(rows.next()){
tempRow = new
Object[]{rows.getString(1),rows.getString(2),rows.getString(3),rows.getString(4),rows.getFloat(5),rows.getInt(6)};
itemTableModel.addRow(tempRow);
}
MainFramePanels.inventory_Panels.itemTable.setModel(itemTableModel);
MainFramePanels.mainFrame.pack();
MainFramePanels.mainFrame.revalidate();
}
catch (SQLException e) {
e.printStackTrace();
}
closeDB();
}
}
here is the delete function code:
static class delOldItem{
delOldItem() throws SQLException{
delItem();
}
public static void delItem() throws SQLException{
String Oprt = "DELETE";
String Dscrpt = ("Delete TYPE("+tableItemType+")
ITEM("+tableItemItem+") SKU("+tableItemSKU+")
SIZE("+tableItemSize+") Thick("+tableItemThick+")");
try {
connectDB();
successPanel = new JPanel();
stmtUpd.executeUpdate("DELETE from catalogue where
UPPER(SKU)=UPPER('"+tableItemSKU+"')");
getLog(Username,Oprt,Dscrpt,null);
new Log();
UIManager.put("OptionPane.okButtonText", "OK");
JOptionPane.showMessageDialog(successPanel,"SUCCESSFUL",
"DELETE", JOptionPane.DEFAULT_OPTION);
new inventoryTableItems();
}
catch (SQLException e) {
e.printStackTrace();
}
closeDB();
}
}
When I delete a row it gives me an error of outofboundsarray... what line
is not correct? so that I will not have an error

No comments:

Post a Comment