在drools规则条件中使用日期进行比较

系统默认支持dd-MMM-yyyy格式.
规则条件编写如下:
$dateInputBox : DateInputBox(verifyDate > "12-Oct-2005")

日期设置如下:
DateFormat df = new SimpleDateFormat("dd-mmm-yyyy",Locale.US);
String s = df.format(new Date());
dateInputBox.setVerifyDate(df.parse(s));

不知道为什么就出现Exception,内容如下:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid date input format: [12-Oct-2005] it should follow: [dd-MMM-yyyy]
	at org.drools.base.evaluators.DateFactory.parseDate(DateFactory.java:526)
	at org.drools.base.evaluators.DateFactory.getRightDate(DateFactory.java:536)
	at org.drools.base.evaluators.DateFactory.access$400(DateFactory.java:46)
	at org.drools.base.evaluators.DateFactory$DateGreaterEvaluator.evaluate(DateFactory.java:389)
	at org.drools.rule.LiteralRestriction.isAllowed(LiteralRestriction.java:62)
	at org.drools.rule.LiteralConstraint.isAllowed(LiteralConstraint.java:81)
	at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:137)
	at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:318)
	at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:162)
	at org.drools.reteoo.Rete.assertObject(Rete.java:175)
	at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
	at org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
	at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:911)
	at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:883)
	at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:684)
	at com.shonetown.common.drools.DroolsTemplate.assertObject(DroolsTemplate.java:85)
	at com.shonetown.common.drools.DroolsTemplate.getWorkingMemory(DroolsTemplate.java:58)
	at com.shonetown.common.drools.service.DateInputBoxService.startRule(DateInputBoxService.java:13)
	at com.shonetown.common.drools.ComponentDroolsServiceProxy.startDateInputBoxDrools(ComponentDroolsServiceProxy.java:58)
	at com.shonetown.common.drools.ComponentDroolsServiceProxy.startComponentDrools(ComponentDroolsServiceProxy.java:49)
	at com.shonetown.common.drools.ComponentDroolsServiceProxy.<init>(ComponentDroolsServiceProxy.java:36)
	at com.shonetown.common.drools.ComponentDroolsServiceImpl.<init>(ComponentDroolsServiceImpl.java:31)
	at com.shonetown.common.drools.ComponentDroolsServiceImpl.main(ComponentDroolsServiceImpl.java:61)

不知道有谁有经验的,帮忙说明下!

后来我通过设置drools.dateformat,让系统支持dd-MM-yyyy,这样就可以了,代码如下:
drl文件:
$dateInputBox : DateInputBox(verifyDate > "12-12-2005")

java代码:
String format = "dd-MM-yyyy";
System.setProperty("drools.dateformat", format);
DateFormat df = new SimpleDateFormat(format);
dateInputBox.setVerifyDate(df.parse("12-12-2008"));

你可能感兴趣的:(java,thread,Access)