how to get column name and database name? (sql)
say i have two table, "countries" and "country groups":
country id, char, 2
country group, char 2,
name, char 10
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"
country group id, "country groups"."country group id"
name, "country groups"."name"
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().
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL