Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PL/SQL中调用此Java程序_Java_Java Stored Procedures - Fatal编程技术网

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

如何在PL/SQL中调用此Java程序,java,java-stored-procedures,Java,Java Stored Procedures,我有一个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 ma

我有一个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();
                                  ^
    TestPorts:16: cannot resolve symbol
    symbol  : variable CommPortIdentifier
    location: class TestPorts
    if (port_id.getPortType() == CommPortIdentifier.PORT_SERIAL)
                                 ^
    TestPorts:20: cannot resolve symbol
    symbol  : variable CommPortIdentifier
    location: class TestPorts
    else if (port_id.getPortType() == CommPortIdentifier.PORT_PARALLEL)
                                      ^
    5 errors
The following operations failed
    source TestPorts: resolution
exiting  : Failures occurred during processing

D:\>

是否可以尝试运行.class文件而不是.java

  • 首先使用javactestports.java编译java类(其输出为TestPorts.class)
  • loadjava-uhr1/hr1@orcl-v-解析TestPorts.class

javax.comm不是标准JDK的一部分,因此在运行
loadjava
之前,您需要使用
ojvmtc
工具手动添加它,请参见首先让我们检查数据库上的CommPortIdentifier.class

作为系统: 从dba\U对象中选择对象名称、状态 其中,对象类型为“%JAVA%”和dbms_JAVA.longname(对象名称)为“%CommPortIdentifier%”

如果未选择任何行,您可以尝试使用loadjava加载包含CommPortIdentifier.class的所需jar库?
然后在数据库上再次编译代码。

理想的方法是使用Javaload将java类加载到Oracle数据库并首先执行,编译类以确保没有错误,然后使用开关加载并编译类文件。并确保所有必要的JAR文件都已加载到数据库中。