Results 1 to 9 of 9
  1. #1
    slipdiegoknot is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default Search box JSP mySQL easy command

    greetings people

    Well I am trying to do a search engine, what I'm doing is:
    1)Getting a string from a textfield
    2)Sending the parameter to a consult in a mySQL command
    which is:
    SELECT * FROM product WHERE productName '"+s1+"'%

    I have a consult like this one that works perfectly:
    SELECT * FROM product WHERE productName A%;

    so the first one should work perfectly too but I dont know what is wrong perhaps is the rest of the code that I havent written but from what you can see here(because it would be too much to post) what do you think is the mistake

    thanks in advance


    BTw: I dont know if this is the right way of doing a search engine but as I told you It worked fine

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Gazing into a crystal ball: use PreparedStatement instead.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    SELECT * FROM product WHERE productName '"+s1+"'%
    SELECT * FROM product WHERE productName A%;

    Neither of those are standard SQL...where's the = ?

    And yes, use a PreparedStatement.

    And also, when posting, provide any errors and exceptions complete with stack traces and relevant code (in code tags). After all "doesn't work" can mean almost anything.

  4. #4
    slipdiegoknot is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    Well as I mentioned they are mySql commands thought you'd know ;) "thanks anyways"

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    Well, MySQL or not...this:
    SELECT * FROM product WHERE productName '"+s1+"'%
    is not going to produce a valid SQL statement.

    And it's not MySQL specific since it doesn't work on MySQL...having just down a similar statement on a local db.

  6. #6
    slipdiegoknot is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    FAILED again it is indeed a mysql command
    check it here
    MySQL Wildcard Filtering using LIKE - Techotopia

    SELECT * FROM tableName WHERE columnName LIKE col%

    it shows you all the columns which have the 'col' as in any part on the word it could show column1, col2, etc

    thanks anyways!

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    Yes.
    And if you look at your command you have no LIKE.
    So that is not a valid SQL statement!

    So I believe this is where I'm supposed to reply back...FAIL!

    Unless you actually give us the code you are working with how on earth are we supposed to guess where you are going wrong?

    So maybe, just maybe, you need to be looking at what you are posting.

  8. #8
    slipdiegoknot is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    hahahaha myBad! but you saw the percentage symbol though

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

Similar Threads

  1. Confusion between Lucene and MySQL fulltext search
    By rehinagrasia in forum Advanced Java
    Replies: 2
    Last Post: 01-10-2011, 10:38 AM
  2. Binary search tree search method
    By chopo1980 in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 01:42 AM
  3. Replies: 0
    Last Post: 10-29-2009, 09:28 AM
  4. Replies: 5
    Last Post: 08-26-2008, 03:43 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 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
  •