Piscean
Piscean

Reputation: 3079

How to write JDO query by using request.getParameter()?

I am using google app engine for the first time. and new in web development. I read the documentation of google app engine but couldn't get one thing. I also googled but couldn't find something easy and simple. According to this query we will get all records with lastName Harold.

 Query query = pm.newQuery(Person.class, "lastName == 'Harold'"); 
 result = (List<Person>) query.execute();

In web application we take parameters by requests. How can i write the same query with only difference that in place of Harold we will use request parameter:

 request.getParameter("lastName");

Thanks in advance.

Upvotes: 0

Views: 154

Answers (1)

Dave W. Smith
Dave W. Smith

Reputation: 24966

You'd do something like

Query query = pm.newQuery(Person.class);
query.setFilter("lastName = lastNameParam");
query.declareParameters("String lastNameParam");
...
List<Person> persons = (List<Person>) query.Execute("Harold");

which is a very slight variation on the first example in http://code.google.com/appengine/docs/java/datastore/jdo/queries.html

Upvotes: 2

Related Questions