H2 shell ALIAS does not work

212 views
Skip to first unread message

Harish AS

unread,
Dec 8, 2015, 3:28:24 PM12/8/15
to H2 Database
Hi,

I am unable to run an ALIAS that i created.When I create an ALIAS it  gets created sucessfully.However when I run the ALIAS it fails.Please see below

First I create the ALIAS for a method called FIELDS which is in the BasicFuntions class.

sql> CREATE ALIAS RR FOR "com.temenos.dbi.storedfunctions.BasicFunctions.FIELD"
;
(Update count: 0, 4 ms)


The creation of the ALIAS itself would fail if the class or the method does not exist.(I have tested that).But in our case,it can identify both and hence lets us create the ALIAS.

But when I immediately run the alias with a call command it says the Method cannot be found.Needless to say I have included the jar inside which this class is present in the CLASSPATH.(That is why the ALIAS is created)

sql> call RR();
Error: org.h2.jdbc.JdbcSQLException: Method "FIELD (com.temenos.dbi.storedfunct
ions.BasicFunctions, parameter count: 0)" not found; SQL statement:
call RR() [90087-172]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
        at org.h2.message.DbException.get(DbException.java:169)
        at org.h2.message.DbException.get(DbException.java:146)
        at org.h2.engine.FunctionAlias.findJavaMethod(FunctionAlias.java:255)
        at org.h2.expression.JavaFunction.<init>(JavaFunction.java:33)
        at org.h2.command.Parser.readJavaFunction(Parser.java:2151)
        at org.h2.command.Parser.readFunction(Parser.java:2190)
        at org.h2.command.Parser.readTerm(Parser.java:2500)
        at org.h2.command.Parser.readFactor(Parser.java:2062)
        at org.h2.command.Parser.readSum(Parser.java:2049)
        at org.h2.command.Parser.readConcat(Parser.java:2022)
        at org.h2.command.Parser.readCondition(Parser.java:1887)
        at org.h2.command.Parser.readAnd(Parser.java:1868)
        at org.h2.command.Parser.readExpression(Parser.java:1860)
        at org.h2.command.Parser.parseCall(Parser.java:4038)
        at org.h2.command.Parser.parsePrepared(Parser.java:326)


I hav also checked that the class is a public class and the method is a static public method.

package com.temenos.dbi.storedfunctions;

import java.io.CharArrayWriter;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Blob;
import java.sql.Clob;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

//import com.temenos.j24.common.PreciseDecimal;
//import com.temenos.j24.common.Util;
//import com.temenos.j24.common.jVar;
//import com.temenos.j24.common.jVarData;
//import com.temenos.j24.common.jVarFactory;

public class BasicFunctions {

/*
     * @derby CREATE FUNCTION j24field (param1 VARCHAR(30000), param2
     * VARCHAR(10), param3 VARCHAR(10), param4 VARCHAR(10)) RETURNS LONG VARCHAR
     * PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME
     * 'com.temenos.dbi.storedfunctions.BasicFunctions.FIELD';
     */
    public static String FIELD(String sStr, String sSeparator, String sOccurence, String sCount) {
        return fGet(sStr, sSeparator, sOccurence, sCount);
    }

The jar is not present in h2*.jar but another jar called TAFJFunctions.jar fyi
Cheers,
harish

Harish AS

unread,
Dec 8, 2015, 11:19:44 PM12/8/15
to H2 Database
sorry.It was rather silly.If we give incorrect number of parameters when we call the method via ALIAS,it gives us a method not found error.It worked wehn I gave the correct number of parameters.I did waste an evening of my time figuring this out though !

Noel Grandin

unread,
Dec 9, 2015, 2:00:38 AM12/9/15
to h2-da...@googlegroups.com
Hi

You are correct, I have improved the error message, sorry about that.

Regards, Noel
Reply all
Reply to author
Forward
0 new messages