Steps to write a Java stored function/procedure are as follows:
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.
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.
% loadjava demodb
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 published Java stored function as follows:
csql> call hello() into :Hello;
Result
=====================
'Hello, Cubrid !!'