1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

JDBC-ODBC Bridge Query Problems with "LIKE" clause

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

  1. atsukoarai86

    atsukoarai86 New Member

    Joined:
    Aug 5, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    systems analyst / db developer
    Location:
    Jupiter
    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:
    Code:
    if(getRecordCount(rs)==0){
                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

    Joined:
    Aug 5, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    systems analyst / db developer
    Location:
    Jupiter
    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

    Joined:
    Aug 6, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    The most likely problem is your LIKE wildcard.

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

    Hope that helps,

    Ted
    OpenLink Software
    Technical Support
     

Share This Page