Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New To Java - JDBC DataSource Independent Code - design suggestions

 
beth ana
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

keyvaluekeyvalue
======================================== | =======================================

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?

Please suggest!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A much better solution is to use an existing ORM tool (Hibernate, Castor, JDO, OJB, etc.). You might want to have a look at one of those.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic