Results 1 to 8 of 8
  1. #1
    hipintu is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default How to get a clob file from data base and pass one instance of that file to another

    Here is my sample code.

    public File getFile(----)
    {
    File file=null;
    try {
    Class.forName(driver);
    Connection conn = DriverManager.getConnection(url, username, pass);
    System.out.println("Connected to EBS");
    //String sql = "SELECT * FROM ebswo where woid='"+origURL+"'";
    String sql = "SELECT * FROM ebswo where woid='wso002'";
    Statement stmt = conn.prepareStatement(sql);
    ResultSet rs = stmt.executeQuery(sql);
    System.out.println();
    while (rs.next()) {
    docName = rs.getString(2);
    System.out.println("Document Name in buildDocInfo>>>>>" + docName);

    file = new File(docName);
    Reader reader = rs.getCharacterStream(3);
    FileWriter writer = new FileWriter(file);
    char[] buffer = new char[1];
    while (reader.read(buffer) > 0) {
    writer.write(buffer);
    }
    System.out.println("File Created in buildDocInfo>>>>");
    writer.close();
    }
    conn.close();

    }
    return file;
    }


    So my requirement is how can I get one instance of the file without storing the file in the local hard disk.

    i.e I have to pass the file file instance dynamically with out storing the parent file into local drive.


    please reply me soon..


    Thanks In advance

    Srinibash
    Last edited by hipintu; 02-09-2011 at 10:55 AM.

  2. #2
    hipintu is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    Please reply someone to my previous thread.

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Rather than reading it and writing it to a file, store it in a byte[] instead. I feel like I didn't understand the problem because that solution is too obvious and simple.

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

    Default

    You haven't told us what you are planning on doing with the Clob data.
    If it's streaming somewhere then pass an OutputStream into that method and stream the contents (getBinaryStream()) to that OutputStream directly.
    "pass one instance of that file to another" makes no sense.

  5. #5
    hipintu is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    What ever be the file i.e CLOB or BLOB, I need to get that file from the Database and without storing that file into any local drive I have to pass one instance of that file to some other java method so that in later stage I can get some of the properties of that file like Doc size, last modified date etc...

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

    Default

    What sort of file is it?
    Presumably there's something about the form that holds things like "last modified date" in the BLOB itself?

    To be honest I'd store that in the db separately. No need to get a blob out if you don't actually need 99% of the data stored in it.

  7. #7
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    You can create a java.io.File instance that doesn't represent an actual disk file, and it can be passed around to different methods like any other object. Is that what you're trying to do?

    Java Code:
    File file = new File("there is no actual disk file by this name");

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

    Default

    I have a feeling the OP wants to read the Blob out and somehow create a File object from this that will have all the data (last modified etc etc) that would have been there when the file was originally on a disk, before being persisted to the database. Which, of course, is not correct.

Similar Threads

  1. Replies: 6
    Last Post: 12-01-2010, 06:31 AM
  2. Retrieving the data posted to a JSP file from HTML file
    By marie in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 10-21-2010, 09:37 AM
  3. Replies: 4
    Last Post: 07-06-2010, 10:40 AM
  4. Replies: 6
    Last Post: 06-05-2009, 12:09 AM
  5. I can't seem to pass a file through a parameter
    By daletron3030 in forum New To Java
    Replies: 5
    Last Post: 01-15-2009, 07:07 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
  •