Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

how to get column name and database name? (sql)

hello,
say i have two table, "countries" and "country groups":

countries:
country id, char, 2
country group, char 2,
name, char 10

country groups:
country group id, char, 2
name, char 10

i use this sql query:
select * from "countries" inner join "country groups" on "countries"."country group"="country groups"."country group id"

and then I execute the query and store the result in a variable rs (ResultSet),
now, i want to produce the list like this in java (according to the ResultSet)

country id, "countries"."country id"
country group, "countries"."country group"
name, "countries"."name"
country group id, "country groups"."country group id"
name, "country groups"."name"

please help,
faizal
[804 byte] By [efm] at [2007-11-11 10:24:32]
# 1 Re: how to get column name and database name? (sql)
Once you get the ResultSet, you can call getMetaData() which will return a ResultSetMetaData object. In the ResultSetMetaData class, there are two methods,getColumnName() and getColumnLabel(), you can use these methods to get your required result. If getColumnName() doesn't give the result in the way you wan't, u can set the label when you are executing the query and the same column label can be retrieved using getColumnLabel().
sudheerprem at 2007-11-11 22:31:27 >