Ich habe ein JTable
in mu eingefügt JFrame
und versuchen Zeilen aus einer Ergebnismenge hinzufügen, aber es istjava.lang.ArrayIndexOutOfBoundsException: 0> = 0 in swing
Exception in thread "AWT-EventQueue-0"java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
der Code unten zeigt:
String billSelect_Sql = "select bill.bill_id, transaction.date, bill.product_desc, bill.quantity, bill.rate, transaction.debt, transaction.crdt, transaction.closing_balance from bill, transaction where bill.user_id = transaction.user_id and bill.user_id = '"+uid+"';";
Statement ST2=conn.createStatement();
ResultSet RS2 = ST2.executeQuery(billSelect_Sql)
int rowCount = 0;
while(RS2.next()){
billing_tab.getModel().setValueAt(RS2.getString("bill_id"), rowCount, 1);
billing_tab.getModel().setValueAt(RS2.getString("date"), rowCount, 2);
billing_tab.getModel().setValueAt(RS2.getString("product_desc"), rowCount, 3);
billing_tab.getModel().setValueAt(RS2.getInt("quantity"), rowCount, 4);
billing_tab.getModel().setValueAt(RS2.getDouble("rate"), rowCount, 5);
billing_tab.getModel().setValueAt(RS2.getDouble("debt"), rowCount, 6);
billing_tab.getModel().setValueAt(RS2.getDouble("crdt"), rowCount, 7);
billing_tab.getModel().setValueAt(RS2.getDouble("closing_balance"), rowCount, 8);
rowCount = rowCount+1;
}
}catch(ClassNotFoundException | SQLException | NumberFormatException e){
JOptionPane.showMessageDialog(null, e);
System.out.println(e);
}
billing_tab ist der Variablenname meiner jTable auf jframe. Zeige Fehler an dem Punkt:
billing_tab.getModel().setValueAt(RS2.getString("bill_id"), rowCount, 1);
Habe ich irgendetwas mit diesem Code hinzufügen verpassen?
Fügen Sie Ihren Code hinzu. –
Können Sie zeigen, wie Sie das Array instanziieren? – yashpandey
Ich denke, dein Tisch hat nicht genug Reihen. Erhöhen Sie einfach die Anzahl der Zeilen in der Tabelle beim Iterieren. –