This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Recordset Get Fields

 
Danie Van Eeden
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, im using a microsoft Connection package to connect to MS SQL Server and im using MS J++ compiler.
After I declare a recordset and populate it with info from a database table, I would like to be able to get the field names from that recordset.
why? because im selecting all records from the database table and I dont know the field names. Ive seen the getField() method, but it only seems to get the value from that specific field, and I have no idea what the getFields() method (note the "s") does.
Im writing a small search engine thingy for a personal project, and
any help would be appreciated.
regards
dve83
 
Arulkumar Gopalan
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to get the column names you can use the interface ResultSetMetaData which has the required methods.getColumnName(int column), getColumnType(int column) .
Sample code:
ResultSet rsObj = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
ResultSetMetaData rsmdObj = rsObj.getMetaData();
int intNumberOfColumns = rsmdObj.getColumnCount();

for(int i=0;i<intNumberOfColumns;i++)
{
String strCoulmnName = rsmdObj.getcolumnName(i);
}

Is that what are you looking for?
 
Jason Menard
Sheriff
Posts: 6450
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to move this to the JDBC forum.
 
Danie Van Eeden
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi and thanks, ill try that out and let know if im still struggling.
regards
 
Danie Van Eeden
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi , im back again.
what do i have to imoprt to get ResultSetMetaData as available class/type.
Im currently using com.ms.fwc.data.* (i think that correctly spelled!?)
and does this resultsetmetadata idea support getting table names from the database as well. Ill most probably start messing about with and figure it out myself, but i just thought id ask.
thanks in advance
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic