zultz
zultz

Reputation: 226

Updating image from SQlite Database

I have a system where the user can input images and save it on the database. What I am trying to do right now is to update the saved image from the database. I tried to insert + ", Image = ?" and pst.setBytes(7, bookImage); on my Update button but it somehow not updating . How can I update the picture?

Btw, without the + ", Image = ?" and pst.setBytes(7, bookImage); on my code, the update button is completely working. Also, I don't get any errors in my code.

Thanks!

Here is the code of my update button:

private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {                                          

        String sql = "UPDATE LibrarySystemDatabase"
                + " SET Title = ?"
                + ", Author = ?"
                + ", Genre = ?"
                + ", Lexile = ?"
                + ", Points = ?"
                + ", Image = ?"
                + " WHERE No = ?";

        try (PreparedStatement pst = conn.prepareStatement(sql)) {
            pst.setString(1, txtTitle.getText());
            pst.setString(2, txtAuthor.getText());
            pst.setString(3, txtGenre.getText());
            pst.setString(4, txtLexile.getText());
            pst.setString(5, txtPoints.getText());
            pst.setString(6, txtNo.getText());
            pst.setBytes(7, bookImage);

            int count = pst.executeUpdate();
            JOptionPane.showMessageDialog(null, count + " Records Updated");
            updateTable();
            clearFields();

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        } finally {
            try {
                rs.close();
                pst.close();
            } catch (Exception e) {
            }
        }
    }    

Upvotes: 2

Views: 140

Answers (1)

Sir Beethoven
Sir Beethoven

Reputation: 358

Your parameters seem to be inverted. Try doing this instead:

pst.setBytes(6, bookImage);
pst.setString(7, txtNo.getText());

Upvotes: 2

Related Questions