gpt4 book ai didi

java - Google App Engine Query Execute 只接受 3 个参数

转载 作者:行者123 更新时间:2023-11-29 05:56:28 25 4
gpt4 key购买 nike

谁能告诉我为什么以下代码在最后一行使用命令“执行”并显示错误消息时导致错误:

The method execute(Object, Object, Object) in the type Query is not applicable for the arguments (Long, Long, Date, Date)

Query q = pm.newQuery(Appointment.class,"AdminID == AID"+
" && EmployeeID == CEID"+
" && Time > STime"+
" && Time < ETime");
q.declareImports("import java.util.Date");
q.declareParameters("Long AID, Long CEID, Date STime, Date ETime");
q.setOrdering("Time");
Appointments = (List<Appointment>) q.execute(AdminID, CurrentEmployeeID, Time1, Time2);

据我所知(错误消息暗示,执行函数最多只能接受 3 个参数,如果是这种情况,有人可以建议如何实现我想做的事情吗?我试过了下面的代码,但是每次运行都会出现解析错误!

Query q = pm.newQuery(Appointment.class,"AdminID == "+AdminID+
" && EmployeeID == "+CurrentEmployeeID+
" && Time > "+Time1+
" && Time < "+Time2);
q.declareImports("import java.util.Date");
q.setOrdering("Time");
Appointments = (List<Appointment>) q.execute();

我得到的解析错误是:

org.datanucleus.store.query.QueryCompilerSyntaxException: Portion of expression could not be parsed: Aug 13 11:44:55 BST 2012 && Time < Mon Aug 13 11:45:05 BST 2012

最佳答案

尝试 executeWithArrayexecuteWithMap .

HashMap<String, Object> params = new HashMap<String, Object>();
params.put( "AID", adminId );
params.put( "CEID", currentEmployeeId );
params.put( "STime", startTime );
params.put( "ETime", endTime );

query.executeWithMap( params );

注意事项:

  1. 变量应该是 lowerCamelCase
  2. startTimeendTimeTime1, Time2
  3. 更具描述性
  4. “Id”通常优于“ID”- What is correct Java naming convention for id?
  5. 您的第二次尝试不会成功,因为它隐式调用了 ..."&& Time > "+ Time1.toString() + ...

关于java - Google App Engine Query Execute 只接受 3 个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11918784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com