Results 1 to 2 of 2
  1. #1
    ipurdi is offline Member
    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    Default Read file from database

    Hello,

    Im new to java and new to this forum, so I hope you will be patience with me :)

    What Im trying to do is this:
    I read a file from database, and I need to show this file directly to the user. This file is saved as Blob in Oracle database and I read it in this way:

    String sql = "SELECT image FROM pictures ";
    PreparedStatement stmt = conn.prepareStatement(sql);
    ResultSet resultSet = stmt.executeQuery();
    File image = new File("D:\\java.gif");
    FileOutputStream fos = new FileOutputStream(image);

    byte[] buffer = new byte[1];

    //
    // Get the binary stream of our BLOB data
    //
    InputStream is = resultSet.getBinaryStream(1);
    while (is.read(buffer) > 0) {
    fos.write(buffer);
    }
    fos.close();

    Now I need to "show" this file to the user but I have no clue how.

    If you can suggest me...any idea will be welcome.

    Thank you in adavnce.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default

    Use a bigger buffer...that's just a suggestion by the way, and not how to show the picture.

    What are you using as a front end?
    Swing?

Similar Threads

  1. Replies: 0
    Last Post: 02-11-2009, 10:53 AM
  2. Replies: 3
    Last Post: 01-29-2009, 11:20 AM
  3. Replies: 1
    Last Post: 10-10-2008, 09:47 AM
  4. how to read a url parameter to query a database
    By kwesiaryee in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-01-2008, 03:38 PM
  5. Replies: 1
    Last Post: 08-08-2007, 02:22 AM

Posting Permissions

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