Versions available for this page: CUBRID 8.3.0 |
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 more information 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 SpCubrid.class
Create a CUBRID stored function and publish the Java class as shown below.
csql> create function hello() return string
csql> as language java
csql> name 'SpCubrid.HelloCubrid() return java.lang.String';
csql> ;xrun
Call the published Java stored function as follows:
csql> call hello() into :Hello;
csql> ;xrun
=== < Result of CALL Command in Line 1> ===
Result
======================
'Hello, Cubrid !!'