Results 1 to 4 of 4
  1. #1
    vrk's Avatar
    vrk
    vrk is offline Member
    Join Date
    Jan 2009
    Posts
    24
    Rep Power
    0

    Question how to insert/retrieve jpg img format from MSAccess???

    Hi all!

    Here is my query...how to insert a jpg image into MSAccess database and also retrive from it in an image format using jsp...

    Thanks in advance!
    vrk.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    1.I have declared the image datatype as OLE
    2.Inserting the image code
    --------------------------
    PreparedStatement psmnt = con.prepareStatement("INSERT INTO IMAGESTORAGE(IMAGE) VALUES(?)");
    File image = new File("Sunset.jpg");
    FileInputStream fis = new FileInputStream(image)
    psmnt.setBinaryStream(1, (InputStream)fis, (int)(image.length()));
    int insertCount= psmnt.executeUpdate();
    System.out.println(insertCount);
    -------------------------------
    3.retreival
    Here iam reading and putting the image in a new file called "SunsetImageRead.jpg"
    psmnt = con.prepareStatement("SELECT IMAGE FROM IMAGESTORAGE");
    ResultSet rs = psmnt.executeQuery();
    if(rs.next())
    {
    InputStream fis1;
    FileOutputStream fos;
    try
    {
    fis1 = rs.getBinaryStream("image");
    fos = new FileOutputStream(new File("SunsetImageRead.jpg"));
    int c;
    while ((c = fis1.read()) != -1)
    {
    fos.write(c);
    }
    fis1.close();
    fos.close();
    }catch(Exception ex)
    {
    System.out.println(ex);
    }//try-c

  3. #3
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Simplest way is to use a BLOB - Binary Long OBject. Check the API docs for the Java object and the SQL type of the same name.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  4. #4
    vrk's Avatar
    vrk
    vrk is offline Member
    Join Date
    Jan 2009
    Posts
    24
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 02-28-2009, 09:17 AM
  2. how to convert one format to another format
    By mahipal_reddy621 in forum New To Java
    Replies: 1
    Last Post: 12-02-2008, 10:21 AM
  3. MSAccess and hibernate
    By bbq in forum JDBC
    Replies: 3
    Last Post: 04-30-2008, 04:38 PM
  4. How to retrieve HttpSession from axis 2.0.
    By snooze-g in forum Advanced Java
    Replies: 0
    Last Post: 10-02-2007, 07:08 AM
  5. how to retrieve the width of the column
    By katie in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 10:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •