Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert image into database

I'm trying to insert an image into the database.

CREATE TABLE ImageTable
(
    Id int,
    Name varchar(50) ,
    Photo varbinary(max) 
)

INSERT INTO ImageTable (Id, Name, Photo) 
SELECT 10, 'John', BulkColumn 
FROM Openrowset( Bulk 'C:\caldophilus.jpg', Single_Blob) as EmployeePicture

It throws me an error.

Cannot bulk load. The file "C:\caldophilus.jpg" does not exist.

Please Help.

like image 414
chinna_82 Avatar asked Feb 15 '12 10:02

chinna_82


People also ask

Can you put images in a database?

A database gives you the opportunity to store photos and other small images in a database table. You can create such a database table for example when you want to create an online photo album with descriptions of your photos. Storing images in a database table is not recommended.

Can you put an image in a SQL database?

1) Bring up SQL Server Management Studio. 2) Connect, and open the database you want to add the image to. 3) Expand the tables, and either add a new table with an appropriate index field, or right click teh table and select design. 4) Add a field called "myImage", and make its datatype "image".

Can I add image in MySQL database?

1 Answer. You can try the below code for inserting an image: INSERT INTO xx_BLOB(ID,IMAGE) VALUES(1,LOAD_FILE('E:/Images/jack. jpg'));


1 Answers

The file is probably on your client PC.
Don't forget that C:\ refers to the server C drive.

like image 189
CompanyDroneFromSector7G Avatar answered Sep 23 '22 02:09

CompanyDroneFromSector7G