This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes To get DB column names dynamically at run time. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "To get DB column names dynamically at run time." Watch "To get DB column names dynamically at run time." New topic

To get DB column names dynamically at run time.

Akshay Lele

Joined: Apr 06, 2009
Posts: 10
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.


wood burning stoves
subject: To get DB column names dynamically at run time.
Similar Threads
How to store & retrieve a video file from database?
better option JdbcTemplate.queryForList(query)
Example of Recursive to Iterative
Dynamic column selection in prepared statement?
Better approach if i have multiple datasources JNDIObjectFactoryBean or JVM Variables