File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Recordset Get Fields 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 » Databases » JDBC
Bookmark "Recordset Get Fields" Watch "Recordset Get Fields" New topic
Author

Recordset Get Fields

Danie Van Eeden
Greenhorn

Joined: Sep 03, 2003
Posts: 13
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


Regards<br />-dve83-
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
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?


Anbudan & Mahalo,<br />Arul<br /> <br />-Not a sun certified Java professional :-)
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
I'm going to move this to the JDBC forum.
Danie Van Eeden
Greenhorn

Joined: Sep 03, 2003
Posts: 13
hi and thanks, ill try that out and let know if im still struggling.
regards
Danie Van Eeden
Greenhorn

Joined: Sep 03, 2003
Posts: 13
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Recordset Get Fields
 
Similar Threads
Present Database Field LIst
Get data from TextField ?
Getting meta data from an Entity bean
update statement seems not working
why rowset exhausted error coming?