Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-02-2008, 08:33 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 195
Rep Power: 2
rjuyal is on a distinguished road
Unhappy 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
  #2 (permalink)  
Old 05-02-2008, 08:38 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 254
Rep Power: 2
sanjeevtarar is on a distinguished road
Default
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, 08:42 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 195
Rep Power: 2
rjuyal is on a distinguished road
Default 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, 08:46 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 254
Rep Power: 2
sanjeevtarar is on a distinguished road
Default
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, 09:03 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 195
Rep Power: 2
rjuyal is on a distinguished road
Default 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 ----

}
}
__________________
i am the future
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-05-2008, 07:49 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 195
Rep Power: 2
rjuyal is on a distinguished road
Default 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.
__________________
i am the future
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-05-2008, 02:54 PM
Member
 
Join Date: May 2008
Posts: 22
Rep Power: 0
Jesdisciple is on a distinguished road
Default
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 03:02 PM.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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

BB 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 05:20 PM
Checking ResultSet (second approach) Java Tip Java Tips 0 02-09-2008 08:39 PM
Best Jsp book with practical approach Saurabh321 New To Java 0 02-05-2008 08:12 AM
Please suggest a database ? Vinuraj CLDC and MIDP 1 01-14-2008 08:48 AM
Suggest me the best practise for accesing database by JSP page saurabh.joshi JavaServer Pages (JSP) and JSTL 3 11-27-2007 06:39 AM


All times are GMT +2. The time now is 12:21 AM.



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