简体   繁体   English

从 SQLite 数据库更新图像

[英]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 = ?"我试图插入 + ", Image = ?" and pst.setBytes(7, bookImage);和 pst.setBytes(7, bookImage); on my Update button but it somehow not updating .在我的更新按钮上,但不知何故没有更新。 How can I update the picture?我怎样才能更新图片?

Btw, without the + ", Image = ?"顺便说一句,没有 + ", Image = ?" and pst.setBytes(7, bookImage);和 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());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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