Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

column names in text file

 
nissan altima
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 38
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic