-1

I created a table for file I put the datatype for file varbinary(MAX) and when I am trying to upload the file it show me:

String or binary data would be truncated

When I wrote insert query like this:

   String sql = "INSERT INTO contacts (first_name, last_name, photo) values (?, ?, ?)";
   PreparedStatement statement = conn.prepareStatement(sql);
   statement.setString(1, firstName);
   statement.setString(2, lastName);

   if (inputStream != null) {
       // fetches input stream of the upload file for the blob column
       statement.setBlob(3, inputStream);
   }

I tried setBinaryStream too but it still gave me same error so please help me how to solve it?

blackpanther
  • 10,998
  • 11
  • 48
  • 78
user1050667
  • 453
  • 1
  • 6
  • 14

1 Answers1

0

The error means that your binary data will be truncated when saving the data in a VARBINARY(MAX) column. Just change the type of your column to BLOB.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332