Java Query for Dates not working out?
hello i am using google app engine and using its database i am trying to retrive the data and make a query and only search for the dates or times i want. so if i want all the input dates off September 09, then it will give me the list of all the september dates.
PersistenceManager pm = PMF.get().getPersistenceManager();
List rules = null;
try {
String query = "SELECT FROM "+
TestRule.class.getName()+
" w开发者_JS百科here"+
" days > 31";
System.out.println("query = "+query);
Query q = pm.newQuery(query);
q.setFilter("curDate < endDate");
q.declareParameters("long curDate");
Date curDate = new Date();
rules = (List) q.execute(curDate.getTime());
resp.setContentType("text/html; charset=UTF-8");
PrintWriter out = resp.getWriter();
if(rules != null) {
out.print("<p> Query result size = "+rules.size()+"</p>");
} else {
out.print("<p> Query returned null </p>");
}
} finally {
pm.close();
}
}
The Test rule class has the Database data and has getters and setters. Would anyone know how to do this if there are other ways than that would be great too. Thank you all
There's another, more compact way of doing this:
Also are you sure about the days > 31
filter?
PersistenceManager pm = PMF.get().getPersistenceManager();
List rules = null;
try {
Query query = new Query(TestRule.class, "curDate < endDate && days > 30");
q.declareParameters("long curDate");
rules = (List) q.execute(new Date().getTime());
return rules;
}finally {
pm.close();
}
精彩评论