HP Nonstop SQLMX (SPJ) Stored Procedure in Javas Getting Started

这一生的挚爱 提交于 2020-04-02 01:14:39

Stored Procedure in Java (SPJ)

HP Nonstop SQLMX, we can code Java program and regist it as a DB Stored Procedure, and then calling it. SPJ is a stored procedure whose body is a static Java methodThe body is known as an SPJ method.
 
1. install JDK JDBC ....... onto oss evn;
2. create a class, the fuction must be "static", becuase we can access the method in the class without instantiate.
  1. publicclassHelloWorld{
  2.     publicstaticvoid testFunc(int a,int b,String[] tst,int[] bigger){
  3.  
  4.         if(a > b)
  5.            bigger[0]= a;
  6.         else
  7.            bigger[0]= b;
  8.  
  9.         tst[0]="The bigger one is: ";
  10.     }
  11. }
 
3. FTP the .java file onto oss;
4. compile it with javac command;
5. Regist, To register SPJs into MX,
    You must be either the schema owner or the super ID. Run below script in mxci to reigist the stored procedure.
  1. >>?SECTION "CREATE ENDER SPJs"
  2. >>CREATE PROCEDURE sos.ecui.testFunc(IN param_a INT, IN param_b INT, OUT tst VARCHAR(20), OUT bigger INT)
  3. +>EXTERNAL NAME 'HelloWorld.testFunc'
  4. +>EXTERNAL PATH '/home/ecui/java/test'
  5. +>LANGUAGE JAVA
  6. +>PARAMETER STYLE JAVA
  7. +>MODIFIES SQL DATA;
  8.  
  9. --- SQL operation complete.
  10.  
  11. >> SHOWDDL SOS.ECUI.TESTFUNC;
  12.  
  13. CREATE PROCEDURE SOS.ECUI.TESTFUNC
  14.   (
  15.     IN PARAM_A INTEGER
  16.   , IN PARAM_B INTEGER
  17.   , OUT TST VARCHAR(20) CHARACTER SET ISO88591
  18.   , OUT BIGGER INTEGER
  19.   )
  20.   EXTERNAL NAME 'HelloWorld.testFunc (int,int,java.lang.String[],int[])'
  21.   EXTERNAL PATH '/home/ecui/java/test'
  22.   LOCATION \P3DEV.$DATA01.ZSDZSGJ5.MKN46G00
  23.   LANGUAGE JAVA
  24.   PARAMETER STYLE JAVA
  25.   MODIFIES SQL DATA
  26.   DYNAMIC RESULT SETS 0
  27.   NOT DETERMINISTIC
  28.   ISOLATE
  29.   ;
  30.  
  31. --- SQL operation complete.
 
6. Grant privileges for invoking the SPJs to other users.
7. Call (or invoke) the SPJs in SQL/MX.
 
  1. >>CALL sos.ecui.testFunc(2,4,?,?);
  2.  
  3. TST                   BIGGER
  4. --------------------  -----------
  5.  
  6. The bigger one is:              4
  7.  
  8. --- SQL operation complete.
  9. >>CALL sos.ecui.testFunc(20,4,?,?);
  10.  
  11. TST                   BIGGER
  12. --------------------  -----------
  13.  
  14. The bigger one is:             20
  15.  
  16. --- SQL operation complete.
 
8. delete this SPJ,
  1. >>DROP procedure SOS.ECUI.TESTFUNC;
  2.  
  3. --- SQL operation complete.
 
 





标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!