• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Srinibash Sahoo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Srinibash Sahoo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic