0

I am trying to enter data into mysql table Fruitbox .But while entering data I am getting error Fruitpdf cannot be null. I created fruitbox table as follows:

Fruitname(varchar(100), Fruitpdf(blob), Fruitprice(int)

Fruitpdf column contains pdf files of fruit. My file mango.pdf in desktop is size of 190 KB.

I wrote following query but getting error "Fruitpdf cannot be null" while executing sql statement.

INSERT INTO Fruitbox (Fruitname, Fruitpdf, Fruitprice) VALUES ('Mango', LOAD_FILE('C:\Users\Tom\Desktop\mango.pdf'), '100');

Where I am wrong ? Any help is much appreciated. Thanking you

3

1 Answer 1

1

MySQL treats a backslash in a string as an escape character. You need to use a double backslash :

LOAD_FILE('C:\\Users\\Tom\\Desktop\\mango.pdf')

See https://dev.mysql.com/doc/refman/8.0/en/string-literals.html

Edit : If it still doesn't work :

  • Is the file on the MySQL server ?
  • Is the 'secure_file_priv' variable set ? (SHOW VARIABLES LIKE 'secure_file_priv';) If so, you will need to place the file under that directory.
  • Does your user have the FILE privilege ?
Sign up to request clarification or add additional context in comments.

2 Comments

I am getting that error still...is there any wrong in my syntax ?
@Tom, see update to answer. The syntax is ok, but it would be better to change the '100' string to 100 as the target column wants an int.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.