Results 1 to 2 of 2
  1. #1
    stalkerism is offline Member
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

    Default Mysql LIKE clause problem

    Java Code:
     
    PreparedStatement s = con.prepareStatement(query);
    String query = "SELECT * FROM customers WHERE cust_id = ? OR cust_ic = ? OR cust_name LIKE '%'?'%'";
    This query does not work. How does i use the LIKE clause with the % together in preparedstatement?

    It does not return me any value even the value is there in the DB

    HELP PLS!!!

  2. #2
    stalkerism is offline Member
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

    Default

    found solution.... :p

    Java Code:
    String query = "SELECT * FROM customers WHERE cust_id = ? OR cust_ic = ? OR cust_name LIKE ?";
                PreparedStatement s = con.prepareStatement(query);
                s.setString(1, id);
                s.setString(2, ic);
                s.setString(3, "%"+name+"%");
    the % must be add in when setString.

Similar Threads

  1. Eclipse / Mysql problem
    By jdevm in forum Eclipse
    Replies: 0
    Last Post: 10-09-2008, 01:16 AM
  2. Using escape sequence with like clause (%)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-14-2008, 09:57 AM
  3. Using escape sequence with like clause (_)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-14-2008, 09:55 AM
  4. mysql driver problem
    By mokingsu in forum JDBC
    Replies: 4
    Last Post: 01-17-2008, 05:27 PM
  5. Mysql problem
    By Nick15 in forum JDBC
    Replies: 2
    Last Post: 05-15-2007, 05:07 PM

Posting Permissions

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