0

I have a Java program connected to a SQL database. I need to retrieve records from a table having a field that starts with a given string. I launched this query:

SELECT s.DATA
FROM TMT_SOLICITUD s, TMT_TRAMITES t
WHERE s.IDTRAMITE='723'
AND s.IDTRAMITE=t.IDTRAMITE
AND s.DATA LIKE '<?xml *'

I know that the table TMT_TRAMITES is not used. We still developing the program and it will be used soon. Ignore that part.

The problem is that the result-set that returned to me is empty. However I if launch the same query through Access, It returns me 4 records (which are correct).

Anyone knows how to use the command LIKE correctly, or the reason why this isn't working?

1
  • 1
    Microsoft Access uses a query langauge that is only similar to SQL but is far from being "real" SQL due to all it's "extension" (using the "wrong" wildcard character is one of them). If you change from Access to a "real" DBMS, make sure to read the manual of your DBMS (and possibly a good tutorial on standard SQL) Commented Apr 15, 2013 at 7:49

3 Answers 3

3

try to use '%' instead of '*': % allows you to match any string of any length (including zero length)

WHERE EMP_name like 'Hew%';

or

WHERE EMP_name like '%Hew';

or

WHERE EMP_name like '%Hew%';
Sign up to request clarification or add additional context in comments.

Comments

2

I have already encountered this kind of problem.

Access SQL doesn't use the same wildcards for the Like command than standard SQL.

As you use a library to access your DB through java, try replacing your

AND s.DATA LIKE '*'

with

AND s.DATA LIKE '%'

AS '%' is the standard wildcard to get any string.

Comments

0

I would try using % instead of *. You can place it anywhere in the query string and use it multiple times if you desire. However, I don't see how it makes sense to use just the wildcard without any other data to narrow it down -- it wouldn't be very useful as is. Unless, you want to match the actual asterisk (I could be mistaken as to your intentions), then use %*%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.