O
O
Orkhan Hasanli2017-12-02 18:16:22
Java
Orkhan Hasanli, 2017-12-02 18:16:22

Record in the database is not updated (JavaFX + JDBC + SQLite) - JavaFX, how to fix it?

Good day, dear forum users.
A couple of weeks since I started learning Java and faced such a problem... I
created a small application using java9 + javafx + jdbc (sqlite) + scenebuilder + maven (intellij idea).
It is necessary that the changed record from the tableView table be updated in the database too. Adding and deleting an entry works, but for some reason changing it doesn't. In this case, no error is displayed.
Database structure id, site, sitName, siteLogin, etc. (total 26 columns). First id primary auto increment
What am I doing wrong or missing?
Codes:

public void sqlupdate(String site, String siteLogin, String sitePass  /* bla-bla */) {
        String updatesql = "UPDATE data SET site=? , " + " siteLogin = ? ," + " sitePass = ? ," + " ftp = ?," + " ftpLogin = ?," + " ftpPass = ?," + "port = ?," + "person = ?," + "personEmail = ?," + "personPass = ?," + "personPhone = ?," + "dbName = ?," + "dbUser = ?," + "dbPass = ?," + "dbHost = ?," + "hostingUrl = ?," + "hostingLogin = ?," + "hostingPass = ?," + "providerUrl = ?," + "providerLogin = ?," + "providerPass = ?," + "otherUrl = ?," + "otherLogin = ?," + "otherPass = ?," + "notes = ? "
                + "WHERE id = ?";
        try {
            SQLiteConfig config = new SQLiteConfig();
            Connection c = db.getInstance().getConnection();
            PreparedStatement pstmt = c.prepareStatement(updatesql);
 
            pstmt.setString(1, site);
            pstmt.setString(2, siteLogin);
            pstmt.setString(3, sitePass);
            /* и т.д.и т.п. Пробовал также использовать геттеры pstmt.setString(1, website.getSite); но как-то безрезультатно*/
 
            // update
            pstmt.executeUpdate();
 
        } catch (SQLException ex) {
            ex.printStackTrace();
            System.out.println("Возникла ошибка при добавлении записи");
        }

Then, for this method, I added a listener (accordingly, the method was added to the body of the AddButtonChange button method)
@Override
    public void AddButtonChange(ActionEvent actionEvent) {
sqlupdate("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
}

When you click on the "Change" button, the information should be updated in the database. However, only the table is updated.
Link to the project: https://yadi.sk/d/VClTsgSI3PpY2j
Screen - 3c894557-b127-45d8-81d2-1015dbf4eb77.png
Thanks in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2017-12-03
@azerphoenix

WHERE id = ?
what value are you passing to id?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question