aspose file tools*
The moose likes I/O and Streams and the fly likes How to get a clob file from data base and pass one instance of that file to another java method.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to get a clob file from data base and pass one instance of that file to another java method...." Watch "How to get a clob file from data base and pass one instance of that file to another java method...." New topic
Author

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

Srinibash Sahoo
Greenhorn

Joined: Feb 09, 2011
Posts: 3
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
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Welcome to the Ranch! Can you please UseCodeTags next time?

A java.io.File object always represents physical files (that may or may not exist). If you need a java.io.File then you have no choice but to write the contents to a file. If you don't you can replace the entire FileWriter with something else, like a StringWriter. This will put the contents in memory only. Afterwards you can call toString() to get those contents as a String.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Srinibash Sahoo
Greenhorn

Joined: Feb 09, 2011
Posts: 3
Thanks for the reply.

But as I told earlier, I need a instance of java.io.File , because later in the program I require to evaluate some of the properties of that file like "file size", "last modified date" etc.

Si please suggest me any solution.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Srinibash Sahoo wrote:Thanks for the reply.

But as I told earlier, I need a instance of java.io.File , because later in the program I require to evaluate some of the properties of that file like "file size", "last modified date" etc.

Si please suggest me any solution.


A couple or three points. Nothing in a CLOB relates to the last modified date so a File will not help you there. You don't need a File.length() to get the length read from a CLOB; that will be available from whatever data structure you have store the file content in. I would doubt if a CLOB is the correct way to store a file content unless you can be very sure that it represents text; it is usually much better to use a BLOB then you can store any file content (binary or text) in it.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Srinibash Sahoo
Greenhorn

Joined: Feb 09, 2011
Posts: 3
Hi James Sabre,

It does not matter what type of file is. My point is, I have to get one file from the Data base and i have to pass that file to one Oracle AutoVue server i.e some other integration where i have to get some of the properties of that file and finally I have to print that file. So printing and all is not the point, but only thing is I have to get that file instance.

So suggest me something about this thread.


Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

As said before:
1) a BLOB in combination with InputStream is a better solution if you allow any file type. CLOB will break your binary files. The StringWriter and String from my example will then be replaced by ByteArrayOutputStream and byte[].
2) the content and size can be retrieved from the String / byte[] created by the StringWriter / ByteArrayOutputStream.
3) the last modified date doesn't make sense as it's going to be the current date/time, unless you take this value from the database.
4) java.io.File works with physical file. Period. You can't work around that.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Srinibash Sahoo wrote:Hi James Sabre,

It does not matter what type of file is. My point is, I have to get one file from the Data base and i have to pass that file to one Oracle AutoVue server i.e some other integration where i have to get some of the properties of that file and finally I have to print that file. So printing and all is not the point, but only thing is I have to get that file instance.

So suggest me something about this thread.


Thanks


Ouch! I feel cut to the bone.

Bye
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get a clob file from data base and pass one instance of that file to another java method....
 
Similar Threads
FileWriter, File Created but no content
java io question, conceptual query
scope problem
FileReader issue
Inserting Image into Oracle.