我已经成功地插入和检索了来自java的sql server 中存储为varbinary(max)的图像和文件。我现在要做的是拥有一个允许用户更新文档文件或图像的jframe。
到目前为止,我已经输入了这个。
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
DBConnection db = new DBConnection();
try {
File pp = new File(pic);
FileInputStream fis = new FileInputStream(pp);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum);
}
person_image = bos.toByteArray();
} catch (Exception e) {
}
try {
File ff = new File(fileName);
FileInputStream fis2 = new FileInputStream(ff);
ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
byte[] buf2 = new byte[1024];
for (int readNum; (readNum = fis2.read(buf2)) != -1;) {
bos2.write(buf2, 0, readNum);
}
docFile = bos2.toByteArray();
} catch (Exception e) {
}
if (txt_doc.getText().isEmpty() || txt_pic.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "Cannot have empty fields");
} else {
try {
query = "UPDATE tourClient SET DocumentFile= '" + docFile + "',Photo= '" + person_image + "'WHERE Name= '" + combo_client.getSelectedItem() + "' ";
PreparedStatement stm = db.getconn().prepareStatement(query);
int val = stm.executeUpdate();
if (val > 0) {
JOptionPane.showMessageDialog(null, "Uploaded successfully!!!");
rs.next();
}
db.getconn().close();
} catch (Exception e) {
System.out.println(e);
}
}
}
我收到此错误 - >不允许从数据类型varchar到varbinary(max)的隐式转换。使用CONVERT函数运行此查询
我看到过之前提出的一些类似的问题,但我仍然无法纠正我的错误。如果有人能告诉我它的完成情况会很棒。