aspose file tools*
The moose likes JDBC and the fly likes Using a resultset to write to a .txt file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using a resultset to write to a .txt file " Watch "Using a resultset to write to a .txt file " New topic
Author

Using a resultset to write to a .txt file

Tim Bryant
Greenhorn

Joined: Jul 30, 2011
Posts: 5
Hello,
I am new to Java and I am trying to write from a SQL resultset("SELECT RecordID,ARNumber,DateUpdated,REVCHANGES FROM Updates") is ther a way I can write the results stright to a database on the mainframe? If this is not possible then I will need to write the result set from resultset query toa text file. Is there any way to write the entire resultset out The only thing I have found is the ability to select individuals fields.

Thanks,
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31074
    
232

Tim,
Welcome to CodeRanch!

Yes. You would loop through all the columns in the result set writing them to a text file. Unless you are running your program on the mainframe, it isn't possible to write directly there.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rufat Babakishiyev
Greenhorn

Joined: Jul 25, 2011
Posts: 7
Tim Bryant wrote:Hello,
I am new to Java and I am trying to write from a SQL resultset("SELECT RecordID,ARNumber,DateUpdated,REVCHANGES FROM Updates") is ther a way I can write the results stright to a database on the mainframe? If this is not possible then I will need to write the result set from resultset query toa text file. Is there any way to write the entire resultset out The only thing I have found is the ability to select individuals fields.

Thanks,


I didn't understand well your question, if you want to write resultSet to txt . etc file , you can you OutputStream. If you want to show ReslutSet on Frame , you can use Jtable or JList.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

Jeanne Boyarsky wrote:Unless you are running your program on the mainframe, it isn't possible to write directly there.


Unless there's a JDBC driver for the mainframe database, of course. Which is quite likely. Then you would just use JDBC to write data into tables on the mainframe.
Tim Bryant
Greenhorn

Joined: Jul 30, 2011
Posts: 5
I am trying to use a resultset from an SQL query to write out to a tempory file. Here is a sample of the code I am trying to use. It seems I am running into a couple of problems
1. My output is not formated correctly .
2. I had to comment this line out to get it to run (out.write(rs.getTimestamp(3));) can you not write timestamp?
3. I was expecting my output to look like this: 142 123456 2011-07-28 00:00:00.0 test
4. Instead my output looks like this Žtest




Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

You'll want to format those things as strings before you write them. Check out the API documentation for BufferedWriter, too, I suspect you haven't seen that yet.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using a resultset to write to a .txt file