aspose file tools*
The moose likes JDBC and the fly likes New To Java - JDBC DataSource Independent Code - design suggestions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "New To Java - JDBC DataSource Independent Code - design suggestions " Watch "New To Java - JDBC DataSource Independent Code - design suggestions " New topic
Author

New To Java - JDBC DataSource Independent Code - design suggestions

beth ana
Greenhorn

Joined: Jul 07, 2004
Posts: 11
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: New To Java - JDBC DataSource Independent Code - design suggestions