Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 259333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:15:19+00:00 2026-05-11T22:15:19+00:00

I have some files stored in a database blob column in Oracle 9. I

  • 0

I have some files stored in a database blob column in Oracle 9.

I would like to have those files stored in the file system.

This should be pretty easy, but I don’t find the right snipped.

How can I do this in java?

 PreparedStatement ptmst = ...
 ResutlSet rs = pstmt.executeQuery();
 rs.getBlob();
 // mistery 
 FileOutputStream out = new FileOutputStream();
 out.write(); // etc et c

I know it should be something like that… what I don’t know is what is commented as mistery

Thanks

EDIT

I finally got this derived from David’s question.

This is my lazy implementation:

PreparedStatement pstmt = connection.prepareStatement("select BINARY from MYTABLE");
ResultSet rs = pstmt.executeQuery();
while( rs.next() ) {
    Blob blob = rs.getBlob("BINARY");
    System.out.println("Read "+ blob.length() + " bytes ");
    byte [] array = blob.getBytes( 1, ( int ) blob.length() );
    File file = File.createTempFile("something-", ".binary", new File("."));
    FileOutputStream out = new FileOutputStream( file );
    out.write( array );
    out.close();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:15:19+00:00Added an answer on May 11, 2026 at 10:15 pm

    You’d want to get the blob as an inputstream and dump its contents to the outputstream. So ‘misery’ should be something like:

    Blob blob = rs.getBlob(column);
    InputStream in = blob.getBinaryStream();
    OutputStream out = new FileOutputStream(someFile);
    byte[] buff = new byte[4096];  // how much of the blob to read/write at a time
    int len = 0;
    
    while ((len = in.read(buff)) != -1) {
        out.write(buff, 0, len);
    }
    

    If you find yourself doing a lot of IO work like this, you might look into using Apache Commons IO to take care of the details. Then everything after setting up the streams would just be:

    IOUtils.copy(in, out);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some .doc binary files stored in my database and i would like
I have a database stored in memory of different files headers. I would like
I have some images in a mysql database stored as BLOB's. The maximum file
I have some files that I would like to rename using regex and powershell,
I have an image file which is stored onto database as a blob (shown
We have some files stored in sql database. On an ASP.NET MVC3 form, we
I have some files stored at amazon. all in private mode, and since I
I have a file stored in the terminal server and there are some inforation
i have some files located in c:\MyApp\file.txt and current executing assenbly in in debud
Lets say I have some pdf files stored on my server and I only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.