DerbyがSQLステートメントでビット演算子をサポートしているかどうかを知りたいです。機能リストで真理値テストがYESであることがわかります。以下は同じのリンクです:
http://db.apache.org/derby/docs/10.2/ref/rrefsql9241891.html
次のようなクエリを実行したい:SELECT a&b FROM APP.TEST;
ありがとう
derbyで関数を定義して、上記の機能を実装してみました。
CREATE FUNCTION BitAnd(a SMALLINT, b SMALLINT) RETURNS SMALLINT
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'derby.routines.BitAnd.bitAnd';
次に、ダービークラスパスCALL SQLJ.install_jarで上記の関数を実行するために、次の関数を呼び出しました。
('path\to\db\functions.jar', 'APP.functions', 0);
SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTYを呼び出します
('derby.database.classpath', 'APP.functions');
上記のsp呼び出しを正常に実行し、その後、次のファイルを使用してjarディレクトリを作成しました。path\to\db\jar\APP\FUNCTIONS.jar.G1340195863482
しかし、Javaコードでこの関数を呼び出そうとすると:
deleteAgentStats = dbConnection.prepareStatement("select bitAnd(a,b) AS \"result\" from APP.TEST");
ResultSet andResult = deleteAgentStats.executeQuery();
if(andResult.next()){
System.out.println("heyyyyyyyyyyyyyyyyyyyyyyyyy ::
"+andResult.getInt("result"));
}
次の例外が発生します:
Caused by: java.sql.SQLSyntaxErrorException: The class 'derby.routines.BitAnd' does not exist or is inaccessible. This can happen if the class is not public.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
at primary.db.AgentStatisticsDAO.deleteAgentStatistics(AgentStatisticsDAO.java:507)
... 11 more
Caused by: java.sql.SQLException: The class 'derby.routines.BitAnd' does not exist or is inaccessible. This can happen if the class is not public.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 28 more
Caused by: java.sql.SQLException: Java exception: 'derby.routines.BitAnd: java.lang.ClassNotFoundException'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
... 25 more
Caused by: java.lang.ClassNotFoundException: derby.routines.BitAnd
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1488)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.derby.impl.services.reflect.ReflectClassesJava2.loadClassNotInDatabaseJar(Unknown Source)
at org.apache.derby.impl.services.reflect.DatabaseClasses.loadApplicationClass(Unknown Source)
at org.apache.derby.iapi.services.loader.ClassInspector.getClass(Unknown Source)
at org.apache.derby.iapi.services.loader.ClassInspector.accessible(Unknown Source)
at org.apache.derby.impl.sql.compile.QueryTreeNode.verifyClassExist(Unknown Source)
at org.apache.derby.impl.sql.compile.StaticMethodCallNode.bindExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.JavaToSQLValueNode.bindExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.ResultColumn.bindExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.ResultColumnList.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 21 more
助けてください。