外部库的 H2 数据库使用 apache.commons

H2 database usage of external library like apache.commons

我正在尝试使用 H2 数据库。我想调用 Apache Commons 库中的方法,即 commons-maths3.jar。

H2.bat 看起来如下:

@java -cp "commons-math3.jar;h2.jar" org.h2.tools.Console %*

但是当访问库方法时如下:

CREATE ALIAS sd for "org.apache.commons.math3.stat.descriptive.moment.StandardDeviation";

我收到 90086 错误。

Class "org.apache.commons.math3.stat.descriptive.moment" not found; SQL statement: create alias sd for "org.apache.commons.math3.stat.descriptive.moment.StandardDeviation" [90086-193] 90086/90086

此外,请建议我如何知道 H2 可以访问某个库,例如 DESCRIBE StandardDeviation。

这里有什么我遗漏的吗?

引自the H2 manual

The method name must be the full qualified class and method name, and may optionally include the parameter classes as in java.lang.Integer.parseInt(java.lang.String, int). The class and the method must both be public, and the method must be static. The class must be available in the classpath of the database engine.

(强调我的)

因此您需要为别名指定静态方法,而不是class名称。

但是StandardDeviation没有静态方法。如果你想使用它,你需要自己编写一个(静态)包装函数(在 Java 中)。