• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help Regarding ResultSetMetaData

 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I have a query which gets records from different tables more than 1 as following:
String sql = "select t1.col1,t1.col2,t2.col1 from table1 t1, table2 t2 where <any condition>";

Now i get the records in the ResultSet variable.
Then i use ResultSetMetaData to get the column Name. But i returns column name with out prefix. It displays "col1" as column Name for both "t1.col1" and "t2.col1". How can i distinguish then that which table's column name is it.
I have also tried the ResultSetMetaData's getTalbeName() method but it returns empty string not the Table Name.
Can anyone tell me how can i get the column name as well as its prefix?
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ali,
Since I am currently using an Oracle database, and since I saw no mention in your post of the database you are using, I can only hope that the following will be relevant for you. In any case, the way I overcome this problem with my Oracle database, and Oracle's (thin) JDBC driver, is to use column aliases, for example:

Of-course, the aliases are completely arbitrary. What I have used above is purely an example to help illustrate my meaning. Feel free to use any alias that you are comfortable with.
Then, using the above example, the column names returned by the "ResultSetMetaData" object (again, for an Oracle database, using Oracle's JDBC driver) will be as follows:
t1c1
t1c2
t2c2
Good Luck,
Avi.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic