This week's book giveaway is in the Java in General forum. We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line! See this thread for details.
New To Java - JDBC DataSource Independent Code - design suggestions
posted 11 years ago
I get a jndi name from the UI based on which I make a connection and create statement. I have stored the table_name_constant,table name and column_name_constant,column name in a table. Once Connection is obtained i am creating the two maps as below.
table_name_constant - Actual Table Name | column_name_constant - Actual Column Name
I am building my SQL query with key passed into SQL
select map1.get(column_name_constant),... from map2.get(table_name_constant) where map1.get(column_name_constant = ?);
I have done the above design to meet the requirement "Add a new data source, no code changes" but the tables are updated at the database side. It is assumed that the structure of tables will remain same but the table names and column names must be dynamic.
If I have explained properly, Is there any better solution than this?