On Sun, Aug 21, 2011 at 12:41 PM, John English <[email protected]>wrote:
>
> Create a Java method:
> public static final int weekNumber (java.sql.Date date) {
> Calendar c = Calendar.getInstance();
> c.setTime(date);
> return c.get(Calendar.WEEK_OF_YEAR);
> }
>
> Now create a function in SQL:
> CREATE FUNCTION WeekNumber(theDate DATE)
> RETURNS INTEGER
> PARAMETER STYLE Java
> LANGUAGE Java
> EXTERNAL NAME 'packageName.ClassName.**weekNumber';
>
> ...and then just use "WeekNumber(aDate)" in the SELECT statement.
>
> A bit simpler than the ugly CASE!
>
Thanks!
If I understand correctly (doesn't get clearer from
http://db.apache.org/derby/docs/10.7/ref/rrefcreatefunctionstatement.html) the
java code must be compiled and present on the classpath of derby - or is it
possible to just feed the uncompiled java-code to derby?
Thanks,
--
/Morten