如何在 PL/SQL 中调用这个 Java 程序

我有一个 Java 程序,它显示了我系统中可用的端口列表。


该程序在命令提示符下运行良好。但是现在我想通过 PL/SQL 使用这个 Java 程序。


但我正面临附加的错误。


花很多时间但不能成功。


下面是我的 Java 程序。


import javax.comm.*;

import java.util.*;


/** List all the ports available on the local machine. **/

public class TestPorts

{

public static void main (String args[])

{


Enumeration port_list = CommPortIdentifier.getPortIdentifiers();


while (port_list.hasMoreElements())

{

CommPortIdentifier port_id = (CommPortIdentifier)port_list.nextElement();


if (port_id.getPortType() == CommPortIdentifier.PORT_SERIAL)

{

System.out.println ("Serial port: " + port_id.getName());

}

else if (port_id.getPortType() == CommPortIdentifier.PORT_PARALLEL)

{

System.out.println ("Parallel port: " + port_id.getName());

}

else

System.out.println ("Other port: " + port_id.getName());

}

} // main

} // class PortList[enter image description here][1]


D:\>loadjava -u hr1/hr1@orcl -v -resolve TestPorts.java

arguments: '-u' 'hr1/hr1@orcl' '-v' '-resolve' 'TestPorts.java'

creating : source TestPorts

loading  : source TestPorts

resolving: source TestPorts

errors   : source TestPorts

    ORA-29535: source requires recompilation

    TestPorts:10: cannot resolve symbol

    symbol  : variable CommPortIdentifier

    location: class TestPorts

    Enumeration port_list = CommPortIdentifier.getPortIdentifiers();

                            ^

    TestPorts:14: cannot resolve symbol

    symbol  : class CommPortIdentifier

    location: class TestPorts

    CommPortIdentifier port_id = (CommPortIdentifier)port_list.nextElement();

    ^

    TestPorts:14: cannot resolve symbol

    symbol  : class CommPortIdentifier

    location: class TestPorts

    CommPortIdentifier port_id = (CommPortIdentifier)port_list.nextElement();

                                  ^


aluckdog
浏览 196回答 3
3回答

九州编程

首先让我们检查数据库上的 CommPortIdentifier.class。作为 SYS: SELECT object_name, status FROM dba_objects WHERE object_type like '%JAVA%' 和 dbms_java.longname(object_name) like '% CommPortIdentifier%';如果没有选择行,您可以尝试使用 loadjava 加载包含 CommPortIdentifier.class 的所需 jar 库?然后在数据库上再次编译您的代码。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java