PL/SQL调用JAVA获取网卡MAC地址

主要是学习PL/SQL调用JAVA的方法.

平台:WINDOWS

1.首先用PL/SQL创建好JAVA 源文件(JAVA source)并进行编译,直到没有错误.

注意调用一些外部JAVA 包的时候,编译的时候可能不报错,直到你执行函数的时候才会错误,错误信息一般为:ORA-29540

create or replace and compile java source named getosmac as
import java.io.*;

public class GetOSMac{
    /**
     * 获取MAC地址
     */
    public static String getMac() {
        String result = "";
        try {

            Process process = Runtime.getRuntime().exec("ipconfig /all");--通过执行dos命令IPCONFIG /ALL来获取

            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.然后创建函数调用该JAVA SOURCE

create or replace function GetMac return varchar2 is
  language java name ' GetOSMac.getMac() return java.lang.String';



3.调用函数.

11:13:04 SYS@orcl> select GetMac AS MAC from dual;

MAC
------------------------------------------------

50-E5-49-17-EC-82

已选择 1 行。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值