Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-02-2008, 09:33 AM
rjuyal's Avatar
Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 92
rjuyal is on a distinguished road
Please suggest me the correct approach!
Hi there,
I am having lods of tables in db.

In a file called ‘databasequery.java’ we have defined static variables to hold queries [ select/delete/insert ].



So it is like, if we want to get the query :-


Code:
Databasequery.yourtablename_select_query; Databasequery.yourtablename_insert_statement; Databasequery.yourtablename_update_statement; Databasequery.yourtablename_anyother_statement;


As there are lods of tables this file is going to be very huge.



What I wanted is, there should be some mechanism to achieve this:-

Code:
DatabaseQuery.YourTableName.SELECT_QUERY; DatabaseQuery.YourTableName.INSERT_QUERY;


also we should be able to access the "YourTableName" only via DatabaseQuery, we should not be able to write like

Code:
YourTableName.SELECT_QUERY YourTableName.INSERT_QUERY

Please guide me..
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-02-2008, 09:38 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Mumbai(India)
Posts: 230
sanjeevtarar is on a distinguished road
Did not understand what exactly you want.

Do you need such a method that will return you on depending the argument you are passing on it.
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-02-2008, 09:42 AM
rjuyal's Avatar
Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 92
rjuyal is on a distinguished road
thanks
Thanks for the reply,

i don' need any function,

but this is just i want to change the approach i am using, there should be different java file for differenet tables. also we should no be able to access those class directly, it should be done via a common class [ databasequery or pick you name ]
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-02-2008, 09:46 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Mumbai(India)
Posts: 230
sanjeevtarar is on a distinguished road
Ok..

Can you post your current code and how you are accessing it.
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-02-2008, 10:03 AM
rjuyal's Avatar
Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 92
rjuyal is on a distinguished road
excerpt Code...
Code:
public interface DatabaseQuery { public static final String TABLE1_SELECT_QUERY = "SELECT * FROM content-suppressed ;)"; public static final String TABLE2_INSERT_QUERY = "INSERT INTO content-suppressed ;) " public static final String TABLE2_SELECT_QUERY = "SELECT * FROM content-suppressed ;)"; public static final String TABLE3_INSERT_QUERY = "INSERT INTO content-suppressed ;) " ; ; ; public static final String TABLE31_SELECT_QUERY = "SELECT * FROM content-suppressed ;)"; public static final String TABLE31_INSERT_QUERY = "INSERT INTO content-suppressed ;) " }

Code:
public class MyDaoImpl extends CommonDataSource implements MyDao{ public List getJobsList( MyDataBind myDataBind ) throws MyBaseDbException { List searchResultList = new ArrayList(); Connection connection = null;; PreparedStatement preparedStatement = null;; ResultSet resultSet = null;; try { String queryString = DatabaseQuery.TABLE3_SELECT_QUERY; // here is want something like Databasequery.table3.SELECT_QUERY , ,please see the 1st post :rolleyes: preparedStatement = connection.prepareStatement( queryString ); -- further processing ---- } }
__________________
Life was much better in 2021
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-05-2008, 08:49 AM
rjuyal's Avatar
Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 92
rjuyal is on a distinguished road
new approach!
i am moving to another approach, that seem to be better than previous.

Code:
public interface databasequery{ public interface Table1{ public interface Fields{ all fields here } public interface Query{ all query here } } public interface Table2{ public interface Fields{ all fields here } public interface Query{ all query here } } }

it is working as i expected:-

Code:
selectQuery = databasequery.Table1.Query.SELECT_QUERY;

do anyone is having better approach or should i stick to this one. Or please let me know if there is any flaw in this approach.
__________________
Life was much better in 2021
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-05-2008, 03:54 PM
Member
 
Join Date: May 2008
Posts: 11
Jesdisciple is on a distinguished road
I think you're using classes/interfaces wrongly... A class should describe a type (or singular/static instance) of object, an object an instance of that type, and an interface a type of class. Maybe a Hashtable<String, Hashtable<String, String>> would work like you want...
Code:
//initialize Hashtable<String, Hashtable<String, String>> databaseQuery = new Hashtable<String, Hashtable<String, String>>(); //get a table's statements Hashtable<String, String> statements = databaseQuery.get("tableName"); //get a specific type of statement for the table String statement = statements.get("statementType");

Or you could do:
Code:
public class DatabaseQuery extends Hashtable<String, Hashtable<String, String>> { //implement special get and set methods if you like }

Last edited by Jesdisciple : 05-05-2008 at 04:02 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opinions on best approach for objects spikey Advanced Java 1 04-11-2008 06:20 PM
Checking ResultSet (second approach) Java Tip Java Tips 0 02-09-2008 09:39 PM
Best Jsp book with practical approach Saurabh321 New To Java 0 02-05-2008 09:12 AM
Please suggest a database ? Vinuraj CLDC and MIDP 1 01-14-2008 09:48 AM
Suggest me the best practise for accesing database by JSP page saurabh.joshi JavaServer Pages (JSP) and JSTL 3 11-27-2007 07:39 AM


All times are GMT +3. The time now is 11:12 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org