cancel
Showing results for 
Search instead for 
Did you mean: 

Java in the database: Invoice Example - NoSuchMethodException

Former Member
0 Kudos
4,204

Hi, I'm working on trying to get the Invoice class from the Java in the Database examples to work. I'm following this guide: http://dcx.sybase.com/1200/en/dbprogramming/pg-java-fields.html

When I try to call the stored procedure (step 2 from that guide), I get this error:

Could not execute statement.
Procedure 'init' terminated with unhandled exception
'java.lang.NoSuchMethodException: Invoice.init(java.lang.String, double,
java.lang.String, double)'
SQLCODE=-91, ODBC 3 State="HY000"
Line 1, column 1
You can continue executing or stop.

CALL init('Shirt',10.00,'Jacket',25.00)

This error would indicate that I somehow installed the Invoice class wrong, yet when I go to Sybase Central > External Environments > Java > All Java Classes I can clearly see the Invoice class listed there. In addition, when I double click on the Invoice class, I can clearly see the method signature for the init function along with all the other functions. This is what I see:

public class Invoice extends java.lang.Object
{
    //Properties
    public static java.lang.String lineItem1Description;
    public static double lineItem1Cost;
    public static java.lang.String lineItem2Description;
    public static double lineItem2Cost;

    //Constructors
    public Invoice();

    //Methods
    public static double totalSum();
    public static double rateOfTaxation();
    public static java.lang.String getLineItem1Description();
    public static double getLineItem1Cost();
    public static java.lang.String getLineItem2Description();
    public static double getLineItem2Cost();
    public static void init(java.lang.String, double, java.lang.String, double);

}

How can it be giving me an error that no such method exists when I can clearly see the method, with a matching signature inside the DB? What am I doing wrong?

I'm on ASA 12 if that helps. Thank you!

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hey, I fixed it! The problem was that the CLASSPATH environment variable wasn't set. Thanks!

Former Member
0 Kudos

Could you post what you did, so anyone else with the same problem could fix it to? Thanks!

Former Member
0 Kudos

Sure, I simply set the CLASSPATH environment variable to include the Java Runtime Environment directory, and the path to my classes.. I delimited the two paths with a semicolon.

Former Member

I do not understand your solution. If you properly installed the JAVA class in the database, then you should not be putting anything in the CLASSPATH. Putting the classes/jars in the classpath will force the classes to be loaded by the system classloader which is not what you want. Please consider undoing your change, rerunning your repro to cause the error and then looking at the server window to see what the stack trace leading to the classnotfound exception is. That will give you and us a better idea of what went wrong.