0

I'm trying to update records in my sqlite database when the button is pressed. I've tried everything and I'm at wits end, please help Here's the button code c is a Connection variable, index is an integer variable that represents user's ID in the db

            @Override
            public void actionPerformed(ActionEvent e) {
                przelewKw = Double.parseDouble(kwotaF.getText());

                nazwaDoP = listaDoP.getItemAt(listaDoP.getSelectedIndex()).toString();

                try {
                    for (int i = 0; i < nazwiska.length; i++) {
                        if (nazwaDoP.contains(idKonta[i]) && nazwaDoP.contains(nazwiska[i])) {
                            if (stanK[index-1] >= przelewKw) {
                                double roznica = stanK[index-1] - przelewKw;
                                try {
                                    String url = "jdbc:sqlite:D:\\SQLiteDB\\Bank.db";
                                    c = DriverManager.getConnection(url);
                                    c.setAutoCommit(false);

                                    PreparedStatement pstmt = c.prepareStatement("update Konta set StanKonta='"+ roznica +"' where IDKonta=' " + index +"'");
                                    pstmt.executeUpdate();
                                    System.out.println(stanK[index-1]);
                                }
                                catch (Exception exc) {
                                    System.out.println(exc);
                                }
                                finally {
                                    try {
                                        if (c != null) {
                                            c.close();
                                        }
                                    }
                                    catch (Exception ex) {
                                        System.out.println(ex);
                                    }
                                }
                            }
                            else {
                                JOptionPane.showMessageDialog(framePrzelew, "Zbyt mało środków na koncie", "Uwaga", JOptionPane.WARNING_MESSAGE);
                            }
                        }
                    }
                }
                catch (Exception ex) {

                }
            }
        });```

pvpkiran
  • 25,582
  • 8
  • 87
  • 134
Modrzejto
  • 3
  • 1

0 Answers0