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 2 of 2

Thread: Comparing search bar input with database

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Comparing search bar input with database

    Hello,
    With my current code i can search on either first name or last name in my database, but im wondering if anyone could explain how i can compare the input to firstname + lastname.
    Further explanation:
    i search for Vincent, it shows all people with the name Vincent. <-- works
    i search for lastNa, it shows all people with the lastname lastNa. <-- works
    Now i need to make it so, that when i enter '' Vincent lastNa''' it shows everyone with that fullname.



    private void nameSearch() {
    searchBarN = zoekS.getText();
    try {
    Statement stat = conn.createStatement();
    DefaultListModel spelerlijst = new DefaultListModel();
    ResultSet result = stat.executeQuery("SELECT * FROM player WHERE firstname LIKE '%" + searchBarN + "%' OR lastname LIKE '%" + searchBarN + "%'");
    ModelItem item;
    while (result.next()) {
    item = new ModelItem();
    item.id = result.getInt("spelerID");
    item.description = result.getString("firstname") + " " + result.getString("lastname ");

    spelerlijst.addElement(item);
    }
    list_speler.setModel(spelerlijst);
    } catch (SQLException | NumberFormatException e) {
    JOptionPane.showMessageDialog(null, "Kan deze naam niet vinden");
    } catch (NullPointerException e) {
    }
    }



    many thanks in advance,
    Vincent


  2. #2
    Member
    Join Date
    Jan 2013
    Posts
    34
    My Mood
    Busy
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default Re: Comparing search bar input with database

    Remember to put your code in a code box, so it formats it and makes it easier to read.

Similar Threads

  1. To check presence of padlock icon in the location bar /address bar
    By Rexy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 25th, 2013, 06:44 AM
  2. Replies: 2
    Last Post: April 6th, 2012, 01:58 AM
  3. Comparing Input to array
    By hbonh in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 28th, 2011, 10:43 AM
  4. Beginner Java Program Help/ txt database search
    By JavaConfused in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 21st, 2011, 09:20 AM
  5. Java Bar graph takes user input to create graph?
    By kenjiro310 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 31st, 2011, 07:37 AM