PL/SQL calls JAVA to obtain the MAC address of the NIC

Source: Internet
Author: User

PL/SQL calls JAVA to obtain the MAC address of the NIC. It is mainly used to learn how PL/SQL calls JAVA. platform: WINDOWS 1. first, use PL/SQL to create and compile the JAVA source file (JAVA source) until there is no error. note that when calling some external JAVA packages, no error may be reported during compilation until you execute the function. The error message is generally: ORA-29540 [java] create or replace and compile java source named getosmac as import java. io. *; public class GetOSMac {/*** get MAC address */public static String getMac () {String result = ""; try {Process process = runtime.getruntime(cmd.exe c ("ipconfi G/all "); -- Obtain InputStreamReader ir = new InputStreamReader (process. getInputStream (); LineNumberReader input = new LineNumberReader (ir); String line; while (line = input. readLine ())! = Null) if (line. indexOf ("Physical Address")> 0) {String MACAddr = line. substring (line. indexOf ("-")-2); result = MACAddr ;}} catch (java. io. IOException e) {System. err. println ("IOException" + e. getMessage ();} return result;} public static void main (String [] args) {System. out. println ("OK !!! "};}2. then create a function to call the java source [SQL] create or replace function GetMac return varchar2 is language java name 'getosmac. getMac () return java. lang. string '; 3. call a function. [SQL] 11:13:04 SYS @ orcl> select GetMac AS MAC from dual; MAC ---------------------------------------------------- 50-e5-49-17-ec-82 1 row has been selected.

Related Article

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.