This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes column names in text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "column names in text file" Watch "column names in text file" New topic

column names in text file

nissan altima

Joined: Jan 11, 2013
Posts: 1
I want to write query results along with cloumn names into text file using Java, I am able to write the results but I dont see any option to wirte the column headers are also in text file. The file should contain column headers 1st and then the query results, any suggestions please?
Vijay Vishwa

Joined: Nov 21, 2010
Posts: 28
You can get the column name indirectly from ResultSetMetaData.

Use the methos ResultSet.getMetaData() to get the ResultSetMetaData and then use ResultSetMetaData.getColumnCount() to get the no. of columns in ResultSet
Next iterate to get each column name using ResultSetMetaData.getColumnName(i)

SCJP 5.0 OCBCD 5.0(Formerly SCBCD)
I agree. Here's the link:
subject: column names in text file
Similar Threads
Hibernate error: ORA-01747: invalid user.table.column, table.column, or column specification
Generate CSV from Resultset
JTable row header or?
Jlist or Jtable?
Trouble with retrieving dates after I create a column alias