0

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?

ShanD
  • 91
  • 1
  • 1
  • 11
  • Please elaborate on "*... but when I try to open it, it says the file is corrupted and for the image it doesn't show the png that I uploaded.*" What tools are you using? Why do you expect to see your binary field rendered? – PM 77-1 May 23 '15 at 02:47
  • What does it mean "*when **I** try to open it*"? Please show that part of the code. – PM 77-1 May 23 '15 at 02:56

0 Answers0