File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 JavaScript Promises Essentials this week in the JavaScript 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
Author

To get DB column names dynamically at run time.

Akshay Lele
Greenhorn

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.

Thanks,

Akshay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To get DB column names dynamically at run time.