I've encountered problems with using functions in Apache Derby, in that I can't get Derby to find my self-defined functions. The typical error message looks like this:
The class 'de.uniba.kinf.projm.hylleblomst.database.sql.utils.GroupConcat' does not exist or is inaccessible.
This can happen if the class is not public.
The documentation states that the method must be public and static. This is what I want to use:
package de.uniba.kinf.projm.hylleblomst.database.sql.utils;
public final class GroupConcat {
public static String groupConcat(String separator, String... arguments) {
StringBuilder result = new StringBuilder("");
for (String arg : arguments) {
result.append(arg + separator + " ");
}
result.delete(result.length() - 2, result.length());
return result.toString();
}
}
Basically I just want to add the GroupConcat functionality to the database which is not provided in Derby by standard. The statement I use to add the function to the DB is this:
CREATE FUNCTION SQL_UTIL.GROUP_CONCAT
( SEPARATOR CHAR, ARGS VARCHAR(255) ... )
RETURNS VARCHAR(2000)
PARAMETER STYLE DERBY
NO SQL LANGUAGE JAVA
EXTERNAL NAME 'de.uniba.kinf.projm.hylleblomst.database.sql.utils.GroupConcat.groupConcat'
I've also packed the GroupConcat class in a jar and added it to the classpath where Derby should be able to find it and added it to the database directly. Here's what I did: The .jar lies in the lib-folder of the project, it is also part of the build path (I'm using Eclipse). Its entry in the CLASSPATH-file of the project looks like this:
<classpathentry kind="lib" path="lib/groupConcat.jar"/>
And for good measure and some desperation I've also added it to my system's classpath:
. ; ..;%DERBY_HOME%\lib\derby.jar;%DERBY_HOME%\lib\derbytools.jar;C:\Users\workspace\kinf-workspace\General\lib
My error is probably very trivial, but I'm quite new to Derby and databases in general, so I'd appreciate any help.
Thanks in advance!