Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cycle through recordset fields

Status
Not open for further replies.

softjack

Programmer
Dec 4, 2005
44
0
0
IN
Hi,
How can know the no. of field in a recordset and cycle through all fields getting name of each field???


can anybody help me on this???



Softjack
 
the word recordset threw me because i think that's a VB term... but I'm assuming that you're using Java given the location of your post. Super easy to do what you're talking about. From the java.sql.ResultSet, you can call getMetaData(), and from the metadata object you can find out tons of stuff. Looks like this (I'm abbreviating):

String sql = "SELECT * FROM....";
Connection con = [establish connection];
Statement stmt = con.createstatement();
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();

then you can call:

rsmd.getColumnCount()
rsmd.getColumnName(int)
rsmd.getColumnType(int) - gives you a java.sql.TYPES int

and so on

that help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top