wood burning stoves 2.0
The moose likes JDBC and Relational Databases and the fly likes Storing the ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Storing the ResultSet" Watch "Storing the ResultSet" New topic

Storing the ResultSet


Joined: Dec 28, 2000
Posts: 11
Is there a way where I can store the result of the query as a InputStream rather than a string. The reason for me to store it as InputStream is that .. the method I am using to process the resultset accepts inputstream only.
right now I have to save the data of the resultset as a file and then get the data from the file in the same program.
Could anyone pls help me
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
If you need to pass the entire ResultSet as one Stream then you can build a String and then create a java.io.StringBufferInputStream object.
If you want to pass individual columns then you can use either ResultSet.getAsciiStream() or ResultSet.getBinaryStream(). Both of those will take only one column at a time specified by using either an int (column number) or String (column name).

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Susan Hoover
Ranch Hand

Joined: Jan 04, 2001
Posts: 64
Would something like this work?

Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
The problem is that the creation of a new ByteArrayInputStream is inside the while loop. bais will end up only with data from the last row. How about something like this. I didn't get a chance to try it out but I think it should work.

[This message has been edited by Thomas Paul (edited January 11, 2001).]
I agree. Here's the link: http://aspose.com/file-tools
subject: Storing the ResultSet
It's not a secret anymore!