简体   繁体   中英

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) {
            }
        }
    }    

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM