更新我的项目时遇到问题,图像BLOB格式[JAVA]
该计划是一个商店,你可以添加项目与照片,你可以更新,搜索,删除,添加等,我可以搜索,删除和添加,但不能编辑我的项目。它一直说它有一个错误的sql语法,我不知道该怎么办。请帮忙更新我的项目时遇到问题,图像BLOB格式[JAVA],java,mysql,image,blob,Java,Mysql,Image,Blob,该计划是一个商店,你可以添加项目与照片,你可以更新,搜索,删除,添加等,我可以搜索,删除和添加,但不能编辑我的项目。它一直说它有一个错误的sql语法,我不知道该怎么办。请帮忙 private void btn_browseActionPerformed(java.awt.event.ActionEvent evt) { fileChooser.setCurrentDirectory(new File(S
private void btn_browseActionPerformed(java.awt.event.ActionEvent evt) {
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
FileNameExtensionFilter filter = new FileNameExtensionFilter("*.IMAGE", "jpg", "gif", "png");
fileChooser.addChoosableFileFilter(filter);
result = fileChooser.showSaveDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
String path = selectedFile.getAbsolutePath();
label_photo.setIcon(ResizeImage(path));
s = path;
tf = "true";
} else if (result == JFileChooser.CANCEL_OPTION) {
System.out.println("No Data");
tf = "false";
} else {
tf = "false";
}
}
我的sql语法有错误,有什么问题吗
public void update() {
try {
Class.forName("com.mysql.jdbc.Driver"); // MySQL database connection
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cake_ordering_system?" + "user=root&password=");
PreparedStatement pstmt = null;
pstmt = conn.prepareStatement("update cake set cake_name=?,cake_description=?,cake_price=?,cake_photo=? where cake_name='" + tf_search + "'");
InputStream is = new FileInputStream(new File(s));
//cake_name
pstmt.setString(1, tf_name.getText());
//cake_description*/
pstmt.setString(2, ta_dc.getText());
//cake_price
pstmt.setString(3, tf_price.getText());
//cake_photo
pstmt.setBinaryStream(4, is);
//execute the query
pstmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Successfully updated a new record!");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
我写这段代码是为了更新PostgreSQL数据库中的图像
private void updateImage(int id, File tempImagem) throws Exception {
try {
FileInputStream fis = new FileInputStream(tempImagem);
PreparedStatement pstm = super.operaConn.getConnDst().getConexao().prepareStatement("UPDATE table SET image = ? WHERE id = ?");
byte[] imagemArray = new byte[(int) tempImagem.length()];
DataInputStream imagemStream = new DataInputStream(new FileInputStream(tempImagem));
imagemStream.readFully(imagemArray);
imagemStream.close();
pstm.setBytes(1, imagemArray);
pstm.setInt(2, id);
pstm.executeUpdate();
pstm.close();
fis.close();
} catch (Exception e) {
throw new Exception("ERRO no metodo updateImagem()", e);
}
}
很好 我忘了删除
)
没有看到它。我只是重新检查了我的数据库,看看它是否更新了,但它仍然是一样的。未收到任何错误,但无法更新所有项目,不仅仅是图像。