Insert Picture into M.S Access/SQL table using Java

Home  »  Java  »  Advance Java  »  Java Database  »  Insert Picture Into Table


The following is a simple Java program which will insert a picture into M.S. Access/SQL table. For this first of all you need to create a M.S.Access database or SQL... but in this example I'm using M.S.Access. Now you need create one table in M.S Access as shown below:


Table Definitions:

Table Name: Img[InsertPicture.mdb]
Primary Key: Nil
Foreign Key: Nil

Column Definition:
Column NameData Type
IDAutoNumber
ImagesOLE Object

Table Description:
Column NameDescription
IDCreate AutoNumber for image id
ImageImage type "OLE Object"



After create table in M.S. Access database now you will create DSN.

Following is the source code of the InsertPicture.java



Now compile the above code using javac compiler and the run program.

C:\jdk1.4\bin javac InsertPicture.java
C:\jdk1.4\bin java InsertPicture



The above code will insert a "laura.jpg" named picture into img table.


Download Database


1 comment:

  1. Good Post! Thank you so much for sharing the post, it was so good to read and useful to improve
    Java Training in Electronic City

    ReplyDelete