Results 1 to 7 of 7
  1. #1
    Join Date
    May 2007
    Posts
    24

    Unanswered: LIKE and PreparedStatement

    Hello,

    I am trying to search for a name, so that the user only need to input part of the name and it will come up.

    firstname LIKE '%?%';

    ps.setString(1, firstname);

    The statement sees the '?' as part of the String to be search, so is there any commands to say that the '?' is used for a preparedstatement and not part of the search string?

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    What is the RDBMS you are using please? I will then move the thread to the appropriate forum and you will likely get an answer.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    May 2007
    Posts
    24
    postgreSQL using java

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    TBH I don't know if this is a java question or a PostgreSQL question.

    Moving to PostgreSQL - let me know if it should be java.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    I would say that it's probably a java issue.

    PostgreSQL uses ANSI standard like wildcards for text searches

    % = any number of characters,
    _ = 1 character.

    ref http://www.postgresql.org/docs/8.2/s...-matching.html

    and

    http://java.sun.com/docs/books/tutor.../prepared.html
    Last edited by loquin; 06-21-07 at 17:42.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  6. #6
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    BTW. I know virtually nothing about Java, but from perusing the java documentation, it appears that you may not want to use the apostrophes (string/date delimiters) in your SQL in a prepared statement. And, if that's the case, you might need to concatenate the wildcard character(s) to the text in the .setstring method call.

    ps.setString(1, "%" + firstname + "%");
    Last edited by loquin; 06-21-07 at 18:13.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  7. #7
    Join Date
    May 2007
    Posts
    24
    Quote Originally Posted by loquin
    BTW. I know virtually nothing about Java, but from perusing the java documentation, it appears that you may not want to use the apostrophes (string/date delimiters) in your SQL in a prepared statement. And, if that's the case, you might need to concatenate the wildcard character(s) to the text in the .setstring method call.

    ps.setString(1, "%" + firstname + "%");
    Thanks I ll try it out, seems safe to do it this way,

Posting Permissions

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