您好我正在使用谷歌应用引擎并使用其数据库我试图检索数据并进行查询,只搜索我想要的日期或时间。所以,如果我希望9月9日之前的所有输入日期,那么它将给我所有9月日期的列表。
PersistenceManager pm = PMF.get().getPersistenceManager();
List rules = null;
try {
String query = "SELECT FROM "+
TestRule.class.getName()+
" where"+
" 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();
}
}
测试规则类具有数据库数据 并有吸气剂和二传手。如果有其他方法,有人会知道如何做到这一点 比那还要好。谢谢大家
答案 0 :(得分:1)
还有另一种更紧凑的方法:
您还确定days > 31
过滤器吗?
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();
}