SELECT DateDiff("n", LastDate, Now()) as datediffs FROM UserLog WHERE ID = 1
当我从查询设计 View (MS Access) 执行此查询时。这让我在几分钟内就变得不同了,就像这样:
datediffs --------- 2826
But when I execute the same query (including static value in where condition ID = 1) from servlet like this:
strSql = "SELECT DateDiff(\"n\", LastDate, Now()) as datediffs FROM UserLog WHERE ID = 1";
recset=stmt.executeQuery(strSql);
它给了我以下错误:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
那我到底是怎么了?
最佳答案
上面的评论的撰写。
如果
SELECT TOP 5 id, lastdate FROM UserLog
运行,那么您需要查看语句的各个其他部分。例如,如果数据库丢失引用,Now() 可能会导致问题。
但是,您报告
I executed SELECT DateDiff(\"n\", LastDate, '20-08-2012 5:15:10 PM') Which did not executed. When I tried this one SELECT LastDate, NOW() FROM ... it was executed successfully. So I suspect the problem is with Datediff() function. (–- @hims056, OP)
这很奇怪,因为 DateDiff 通常不能在 MS Access 之外工作。但是,我注意到Oracle Bugs中报告了此问题。 。在评论中,有人提到,在他或她的案例中,问题是列名错误,因此可以使用 ACE 而不是 Jet 进行连接。或者,正如您所说,“在几分钟内从 Java 获取 datediff”。
关于java - 参数太少。预期 1 个错误 - 使用 MS Access 的 DateDiff 函数时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12035536/