Dies ist der Code, den ich Daten aus jtable zur Datenbank einfügen verwendet:Einfügen von Daten aus jtable zu SQLite-Datenbank
for(int i=1 ; i <= table.getRowCount() ; i++){
String productid = table.getValueAt(i, 0).toString();
String name = table.getValueAt(i, 1).toString();
String quantity = table.getValueAt(i, 2).toString();
String totalprice = table.getValueAt(i, 4).toString();
try {
String query = "insert into sales (productid,customerid,name,quantity,discount,totalprice,paymentmethod) values (?,?,?,?,?,?,?)";
pst = con.prepareStatement(query);
pst.setString(1, productid);
pst.setString(2, customerid.getText());
pst.setString(3, name);
pst.setString(4, quantity);
pst.setString(5, discount.getText()+"%");
pst.setString(6, String.valueOf(totalprice));
pst.setString(7, paymethod.getSelectedItem().toString());
pst.execute();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
und wenn ich auf die Schaltfläche Speichern klicken, um es ist mir ein Fehler.
Exception in thread "AWT-Eventqueue-0" java.lang.ArrayIndexOutOfBoundsException: 1> = 1 bei java.util.Vector.elementAt (unbekannte Quelle) bei javax.swing.table.DefaultTableModel. getValueAt (Unknown Source) bei javax.swing.JTable.getValueAt (Unknown Source) bei gestioner.Sale $ 8.actionPerformed (Sale.java:332) bei javax.swing.AbstractButton.fireActionPerformed (Unknown Source)
pls Fehler stacktrace – Cootri
Exception in thread "AWT-Eventqueue-0" java.lang bieten. ArrayIndexOutOfBoundsException: 1> = 1 \t bei java.util.Vector.elementAt (Unknown Source) \t bei javax.swing.table.DefaultTableModel.getValueAt (Unknown Source) \t bei javax.swing.JTable.getValueAt (Unknown Source) \t bei gestioner.Sale $ 8.actionPerformed (Sale.java:332) \t bei javax.swing.AbstractButton.fireActionPerf ormed (Unbekannte Quelle) –
Wenn Sie zwei Zeilen haben, zählen Sie von 1 bis 2? – hagello