Insert picture in MySQL using Netbeans 5.5

Can anyone help me how to insert a picture in MySQL database by using Netbeans 5.5?

I understand that we need to use BLOB as the data type, but how to make MySQL read the location of the picture?

As an example, in table cars,

I have set the datatype VARCHAR for carid, name, vendor and type.

While for pic, I selected BLOB as its datatype.

How I insert data into the table?

I choose Execute Command at carid(primary key) and enter the information.

insert into cars (carid, name, vendor, type,pic) values ('N1','Skyline GT-R','Nissan','4WD',C:\\Documents and Settings\\My Document\\car1.jpeg)

However, I got wrong in term of assigning the value for pic. What should I do?

Please help me.

Thank you in advance.

[783 byte] By [Natasha24a] at [2007-11-27 9:59:53]
# 1
put the binary data there instead of the filename, that means you would need to read the file in first.
robtafta at 2007-7-13 0:30:58 > top of Java-index,Java Essentials,Java Programming...
# 2
May I know what do you mean by binary data of the picture?I really don't get it.
Natasha24a at 2007-7-13 0:30:58 > top of Java-index,Java Essentials,Java Programming...
# 3
> Can anyone help me how to insert a picture in MySQL> database by using Netbeans 5.5?Never ask questions like this, it's really stupid. Yoou don't do anything with Netbeans. You want to know how to do it in Java. Just leave it like that.
cotton.ma at 2007-7-13 0:30:58 > top of Java-index,Java Essentials,Java Programming...
# 4

> May I know what do you mean by binary data of the

> picture?

>

> I really don't get it.

We can see that.

First of all, you do not, as you were trying, just give MySQL a filepath and have it do some magic. That won't work to store the actual image contents in the database.

So what should you do? Create a PreparedStatement. Get the content of the image file (using some sort of stream). Bind the content of the image to your PreparedStatement. Execute the insert.

cotton.ma at 2007-7-13 0:30:58 > top of Java-index,Java Essentials,Java Programming...