[英]Updating image from SQlite Database
我有一个系统,用户可以在其中输入图像并将其保存在数据库中。 我现在想要做的是更新数据库中保存的图像。 我试图插入 + ", Image = ?" 和 pst.setBytes(7, bookImage); 在我的更新按钮上,但不知何故没有更新。 我怎样才能更新图片?
顺便说一句,没有 + ", Image = ?" 和 pst.setBytes(7, bookImage); 在我的代码上,更新按钮完全有效。 此外,我的代码中没有任何错误。
谢谢!
这是我的更新按钮的代码:
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) {
}
}
}
您的参数似乎被反转了。 尝试这样做:
pst.setBytes(6, bookImage);
pst.setString(7, txtNo.getText());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.