Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Searching Data

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Lightbulb Searching Data

    Hi!

    I am going to create search facility for my package.So what i have planned,
    going to keep one common Search Jsp and then one java class for getting data from the database send the data to the servlet, In the servlet displaying the data in html format and then send back ths html format to common jsp page.....

    My doubt is i have arround 10 search criteria like,... Customer search,Item Search,Lot Search,etc...
    so i have decided to make it common Search,..

    In java class i am going to keep Two Methods,.....

    1.Method(String Searchkey,String SearchType)
    2. Method(String SearchType);

    So inside Method,...Based on SearchType (eg:CustomerSearch,Item Search)
    Executing query and fetching the data and set into arraylist and pass into the servlet,.......

    So this is my logic,....is ths okay ?

    Please Answer ths quests

    1 . Shall i keep common two method and inside method by
    based on if SearchType.equals("CustomerSearch") excuting query

    (OR)

    shall i create different methods for different
    search,eg: CustomerSearch(),ItemSearch() like ths,...

    Which one is efficient one?

    Hope U Understand my doubt,....Reply me soon........




    Thanks


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Searching Data

    You could do it that way, but I'm not sure I understand method2, it only takes the search type, so what are you searching for then or are you just listing all of that type?

    // Json

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Lightbulb Re: Searching Data

    Yes..!

    I am going to display all the data,if suppose the user not giving specific keysearch....
    So,..which one i should take,...can u tell me which method i should follow,....and also why?....for clear my knowleadge...if i am using common method,...thr will be more if cond inside method right?...so 'll it affect the performance of my coding?...

    Thanks...

  4. #4
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Searching Data

    Usually when I do JSP/Servlet and use persistence through a database I have a DAO for each table more or less as well as a sort of manager that uses the DAO to access the database. The manager it self will be the one with the logic before inserts and after selects so to speak.

    For instance a way of doing your thing could be to have a CustomerManager, ItemManager etc.

    public class CustomerManager {
     
        public List<CustomerBean> search(final String search) {
            // TODO: Create the logic that calls off to the DAO and gets the search results back.
     
           // For example this could be a simple query such as
           // "SELECT customerid,customername FROM customers WHERE customername LIKE '%?%'"
           // where the ? represents the search string. Just make sure you escape it or use the
           // correct tools for accessing the database.
     
           // Of course you can compliment this method by taking another argument for what field in the table you
           // wish to perform the search on, for instance you might want to search for a customer by id.
        }
     
        public List<CustomerBean> getCustomers() {
            // This is a method that returns ALL customers from the database
        }
     
        public CustomerBean getCustomer(final int customerId) {
            // Select the customer with a specific customer id and return that  customer.
        }
    }

    You will of course need other methods as well, such as add and delete customer and maybe also a setCustomer method for changing the data of a customer.

    I hope this helps somewhat.


    For another approach which might be somewhat over course, I've implemented another search on my sites lately were I use Apache Lucene - Overview to index and search for my products.

    Whenever I add or remove a product from my database I add/remove an index record using Lucene. When a user then searches for a product I just return some of the indexed data which matches the search criteria. Then I print out a list of these products and thats it. When you click one of the links it actually selects the product from the database and displays the product page.

    // Json

Similar Threads

  1. Data is getting corrupt in Jscrollpane
    By ruchika in forum AWT / Java Swing
    Replies: 0
    Last Post: September 1st, 2009, 10:41 AM
  2. problem in retrieving data via RMS
    By solaleh in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: August 30th, 2009, 05:46 AM
  3. .xls data structure
    By helloworld922 in forum JDBC & Databases
    Replies: 3
    Last Post: August 20th, 2009, 07:12 PM
  4. I can't key in the data
    By muffin in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 10th, 2009, 11:03 PM
  5. Spanish Java programmers
    By koko10ar in forum Project Collaboration
    Replies: 0
    Last Post: November 15th, 2008, 12:31 PM