Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Location
    España
    Posts
    3

    Unanswered: LIKE clause in SQL Server 2000

    Hello,

    I connect to a SQL Server 2000(SP3) database using
    jdbc driver (sun.jdbc.odbc.JdbcOdbcDriver).
    When I use the LIKE clause, the statement always returns 0 rows.

    Any idea?

    Thanks for your help!!!

  2. #2
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447

    Re: LIKE clause in SQL Server 2000

    I hope you are using '%' as wildcard ?!
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

  3. #3
    Join Date
    Sep 2003
    Location
    España
    Posts
    3

    Re: LIKE clause in SQL Server 2000

    Originally posted by DoktorBlue
    I hope you are using '%' as wildcard ?!
    Yes, the program code is :

    sel = "select * from mitabla where userc like ? ";
    pstmt = con.prepareStatement(sel);
    String userc = "p";
    userc = "%" + userc + "%";
    pstmt.setString(1, userc);
    rs = pstmt.executeQuery();

    while (rs.next()) {

    ....

    There are rows with the userc string in the database and I can see them when I run this sentence directly in then query analyzer.

  4. #4
    Join Date
    Aug 2003
    Location
    Delft, The Netherlands (EU)
    Posts
    447

    Re: LIKE clause in SQL Server 2000

    Can you log, which SQL statement is finally produced, when this line executes:

    rs = pstmt.executeQuery();

    ? It should look like

    select * from mitabla where userc like '%p%'

    which gets all records where userc contains a 'p' at any position.
    Make everything as simple as possible, but not simpler! - A. Einstein
    DB Problems? DB Explorer, BTrieve Re-engineering, DB Conversions & ETL? Conversion Tool

  5. #5
    Join Date
    Sep 2003
    Location
    España
    Posts
    3

    Re: LIKE clause in SQL Server 2000

    Originally posted by DoktorBlue
    Can you log, which SQL statement is finally produced, when this line executes:

    rs = pstmt.executeQuery();

    ? It should look like

    select * from mitabla where userc like '%p%'

    which gets all records where userc contains a 'p' at any position.
    I don't know to see the log :-( but I think the SQL statement is correctly....
    I'm also installed the SP3 for SQL Server 2000 and the SP1 for jdbc for SQL Server 2000.
    If I execute this code:
    sel = "select * from mitabla where userc like ? ";
    pstmt = con.prepareStatement(sel);
    userc = "%p%";
    pstmt.setString(1, userc);
    returns 0 rows.

    but if I execute :
    sel = "select * from mitabla where userc like '%p%' ";
    pstmt = con.prepareStatement(sel);
    returns 3 rows (correctly).

    I don't have idea :-(
    I'm going to do it like this:
    userc="p";
    sel = "select * from mitabla where userc like '%"+userc+"%'";
    pstmt = con.prepareStatement(sel);
    (also correctly, 3 rows)

    thanks very much!

Posting Permissions

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