views:

130

answers:

3

How do I write where clause where the value has spaces:

Actually I am using openJPA and I have to set parameter. The value i will be setting has a space, eg: String somevalue="firstname lastname"; query.setparameter(somevalue);

I did this but doesnot work. Any suggestion will be appreciated. Thanks.

+2  A: 

That should work. The space within the quotes is valid. Perhaps there are spaces after the lastname, or the casing of lastname is incorrect.

akf
actually query.setParameter(value with space); is not workingdo I need to do some special thing with query.setparameter()
+1  A: 

That syntax does indeed work; you must be typing in a name that does not exist.

sqlite> CREATE TABLE FOO (name TEXT);
sqlite> INSERT INTO FOO VALUES('joe smith');
sqlite> SELECT * FROM FOO WHERE name = 'joe smith';
joe smith

If this is a one-off search, you might be better off trying the LIKE operator to find the match:

sqlite> SELECT * FROM FOO WHERE name LIKE '%smith%';
joe smith
Mark Rushakoff
actually query.setParameter(value with space); is not workingdo I need to do some special thing with query.setparameter()
A: 

There's nothing wrong with that query.

If it's not returning results, it's because you've got a problem with your data. Are you storing as 'char' or 'varchar'? If it's 'char', then you'll have extra padding characters in there to watch for.

jvenema
actually query.setParameter(value with space); is not workingdo I need to do some special thing with query.setparameter()