Results 1 to 7 of 7
  1. #1
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    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 :-


    Java 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:-

    Java 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

    Java Code:
    YourTableName.SELECT_QUERY
    
    YourTableName.INSERT_QUERY

    Please guide me.. :(

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    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,संजीव

  3. #3
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    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 :) ]

  4. #4
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Ok..

    Can you post your current code and how you are accessing it.
    sanjeev,संजीव

  5. #5
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default excerpt Code...

    Java 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 ;) "
    }

    Java 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

  6. #6
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default new approach!

    i am moving to another approach, that seem to be better than previous.

    Java 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:-

    Java 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

  7. #7
    Jesdisciple is offline Member
    Join Date
    May 2008
    Posts
    22
    Rep Power
    0

    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...
    Java 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:
    Java 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.

Similar Threads

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •