Using Wildcard ( * ) characters in SQL Strings

Posted on 2003-02-18
Medium Priority
Last Modified: 2010-03-31
I have a simple java program that stores data in a MS Access Database, however I have problems when I try to use wildcard characters in SQL queries.  The query is passed to the DB fine, but the ResultSet returned contains no records even when there should be.  I have even gone to the extent of creating a query in Access, and then pasting the SQL code into my java app, but even that won't work.  Any suggestions would be most appreciated.
Question by:sre22
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 7979427
Is it possible to see you code? ( with the query too of course )

Author Comment

ID: 7979637
It's not really any specific line of code that I can't get to work, but here is an example of what I am doing:

String sQuery = "SELECT Name " +
                "FROM TroubleCall " +
                "WHERE Name Like 'A*';"

//running this query straight from Access returns a list of people in the table whose name starts with A.  But when you pass the query using jdbc:odbc, nothing is returned.  Here is how I pass it to the DB:

Connection con = null;
  String url = "jdbc:odbc:TroubleCall";
  con = DriverManager.getConnection(url);
catch(ClassNotFoundException ea){}
catch(SQLException eb){}
catch(Exception ec){}

Statement stat = null;
  stat = con.createStatement();
catch(SQLException e){}

ResultSet rs = null;
  rs = stat.executeQuery(query);
catch(SQLException e)

The code is actually broken up into methods, but this gives the general idea.  I don't catch any Exceptions, and I do get a ResultSet, but the ResultSet contains no records.

Accepted Solution

umangjoshi earned 200 total points
ID: 7979827

try this:
String sQuery = "SELECT Name " +
               "FROM TroubleCall " +
               "WHERE Name Like 'A%';"


Author Comment

ID: 7980037
Thanks. This worked perfectly.  I just joined this message board today and I am very impressed with the responsiveness.  I posted the message this afternoon, and received 2 replies, including the answer in the same day.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question