Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 



How to Write Java Stored Function/Procedure

Steps to write a Java stored function/procedure are as follows:

  1. Check the cubrid.conf file
  2. Write and compile the Java source code
  3. Load the complied Java class into CUBRID
  4. Publish the loaded Java class
  5. Call the Java stored function/procedure
Check the cubrid.conf file

By default, the java_stored_procedure is set to no in the cubrid.conf file. To use a Java stored function/procedure, this value must be changed to yes. For details on this value, see Other Parameters in Database Server Configuration.

Write and compile the Java source code

Compile the SpCubrid.java file as follows:

public class SpCubrid{

    public static String HelloCubrid() {

        return "Hello, Cubrid !!";

    }

    public static int SpInt(int i) {

        return i + 1;

    }

    public static void outTest(String[] o) {

        o[0] = "Hello, CUBRID";

    }

}

 

%javac SpCubrid.java

Here, the Java class method must be public static.

Load the compiled Java class into CUBRID

Load the compiled Java class into CUBRID.

% loadjava demodb

Publish the loaded Java class

Create a CUBRID stored function and publish the Java class as shown below.

csql> create function hello() return string

as language java

name 'SpCubrid.HelloCubrid() return java.lang.String';

Call the Java stored function/procedure

Call the published Java stored function as follows:

csql> call hello() into :Hello;

  Result

=====================

'Hello, Cubrid !!'