1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

JDBC-ODBC Bridge Query Problems with "LIKE" clause

Discussion in 'Java' started by atsukoarai86, Aug 6, 2010.

  1. atsukoarai86

    atsukoarai86 New Member

    Hello Everyone,

    I am connecting to a MS Access database using the DriverManager class and JDBC-ODBC Bridge driver. I am having trouble with a query using the "LIKE" clause in MS Access. When I run the query in Access, it returns results as it ought to, but when I attempt to use this string of SQL in a prepared statement, it returns no records.

    Here is my code:
                System.out.println("No records restrieved for :\n" + strSQL + "\nReassigning query expression");
                strSQL = "SELECT * FROM tblNAmes WHERE " + c + " LIKE '*"+ crit + "*' ORDER BY " + c + ";";
                System.out.println("New Statement: " + strSQL);
                System.out.println("Assigning result set");
                ps = conn.prepareStatement(strSQL, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                rs = ps.executeQuery();
            int count = getRecordCount(rs);
            System.out.println("Records Retrieved: " + count);
    Here is the output I receive:
    All of my other query expression (not using "LIKE") work perfectly fine. Does anyone see any glaring errors in this code? I have only recently become familiarizing myself with these tools, so any assistance would be greatly appreciated.

    Thank you in advance!
  2. atsukoarai86

    atsukoarai86 New Member

    fifteen people have looked at this thread and NO ONE has any idea what might be a solution?

    Back to the old drawing board.
  3. OpenLink

    OpenLink New Member

    The most likely problem is your LIKE wildcard.

    Instead of
    SELECT * FROM tblNAmes WHERE strFirstName [B]LIKE '*a*'[/B] ORDER BY strFirstName;
    SELECT * FROM tblNAmes WHERE strFirstName [B]LIKE '%a%' [/B]ORDER BY strFirstName;

    Hope that helps,

    OpenLink Software
    Technical Support

Share This Page