Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a resultset to write to a .txt file

 
Tim Bryant
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rufat Babakishiyev
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic