• 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

To get DB column names dynamically at run time.

 
Greenhorn
Posts: 11
  • 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 Spring 2.0 project. For data access good old JDBC code is used i.e specifying SQL query in a String variable (the code was written some time back so cant change that part).

There are 2 data bases of different vendors and they have the same tables, at one time though only one will be in use. The problem is column name of a table in one DB is a reserved word in other DB. To get over this in other DB the column name has been changed.

Here in lies my problem, as if there is switching from DB1 to DB2 the SQL query will have to change so as to reflect the correct column name.

The two ways that i have figured out around this is as follows:

1. Set an environment variable in the Websphere admin console. This would hold the value of the column name. In case of DB switching just change this variable to a appropriate value. The java code will say

Hence no change in application code.

2. Use DatabaseMetadata interface's getColumns() method.

Is there any other way to do this, especially in context of existing Spring classes(not JDBCTemplate etc) or some other way.

I would really appreciate any help on this.

Thanks,

Akshay
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic