?
Solved

Using Wildcard ( * ) characters in SQL Strings

Posted on 2003-02-18
4
Medium Priority
?
179 Views
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.
0
Comment
Question by:sre22
  • 2
4 Comments
 
LVL 1

Expert Comment

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

Author Comment

by:sre22
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;
try
{
  String url = "jdbc:odbc:TroubleCall";
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  con = DriverManager.getConnection(url);
}
catch(ClassNotFoundException ea){}
catch(SQLException eb){}
catch(Exception ec){}

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

ResultSet rs = null;
try
{
  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.
     
0
 
LVL 1

Accepted Solution

by:
umangjoshi earned 200 total points
ID: 7979827

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

0
 

Author Comment

by:sre22
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

580 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