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


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

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

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Posts
    18

    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

  2. #2
    Join Date
    Dec 2006
    Location
    Kerala,India
    Posts
    51
    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().

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center