I wrote a SQL UPDATE statement to update document file and photo stores as varbinary(max) in the DB. At first I got an error saying Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query
So I changed the code and did it like this.
try {
//SET Varbinary_Col = CAST(Varbinary_Content as VARBINARY)
query = "UPDATE tourClient SET DocumentFile= CONVERT(varbinary(max),'"+docFile+"'),Photo= CONVERT(varbinary(max),'"+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);
}
After I run the above query in netbeans, i get the Joption message saying uploaded successfully. I have another jframe in netbeans, which has a query that SELECTS all document files, Images and shows it in a jtable. When I click a row in jtable the image is shown in a label and the document is opened but when I try to open it, it says the file is corrupted and for the image it doesnt show the png that I uploaded.
Have I written the statement correctly? Anything I have to change?