Example of calling executable programs in PL/SQL using Java

Source: Internet
Author: User

/* Replace the username */
Call dbms_java.grant_permission ('frgt _ uat', 'sys: Java. Io. filepermission ',' <all files> ', 'execute ');

Create or replace Java source named "jtns"
As
Import java. Io. inputstream;
Import java. Io. inputstreamreader;
Import java. Io. ioexception;
Public class jtns {
Public static string getfing (string seed ){
/* Note: When this error occured
ORA-29532: Java Call terminated by uncaught Java exception: Java. Lang. nullpointerexception
Just place the full path of the EXE
Ex:
String command = "/home/Oracle/product/9.2/bin/tnsping" + seed;
*/
String command = "tnsping" + seed;
String pingres = NULL;
Process process;
Inputstreamreader IR = NULL;
Char C [] = new char [1024];
Try {
Process = runtime.getruntime(cmd.exe C (command );
IR = new inputstreamreader (process. getinputstream ());
While (IR. Read (C, 0, 1024 )! =-1 ){
Pingres = new string (C );
}
IR. Close ();
} Catch (ioexception Io ){};
If (pingres = NULL) pingres = "cant find tnsping ";
Return pingres. Trim ();
}
};
/

Create or replace function gettnsping (SID varchar2) return varchar2
As language Java
Name 'jtns. getfing (Java. Lang. String) return java. Lang. string ';
/

Create or replace function isseedup (SID varchar2) return Boolean
As
Stat Boolean: = false;
Res varchar2 (32767): = gettnsping (SID );
Begin
Stat: = case
When instr (Res, 'OK')> 0 then true
Else false
End;
Return Stat;
End;
/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.