【问题标题】:How to Call This Java Program in PL/SQL如何在 PL/SQL 中调用这个 Java 程序
【发布时间】:2018-08-12 11:45:56
【问题描述】:

我有一个显示系统中可用端口列表的 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:\>

【问题讨论】:

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

标签: java java-stored-procedures


【解决方案1】:

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

  • 首先使用 javac TestPorts.java 编译你的 java 类(它的输出是 TestPorts.class)
  • loadjava -u hr1/hr1@orcl -v -resolve TestPorts.class

【讨论】:

    【解决方案2】:

    javax.comm 不是标准 JDK 的一部分,因此您需要在运行 loadjava 之前使用 ojvmtc 工具手动添加它,请参阅 ojvmtc tool doc

    【讨论】:

      【解决方案3】:

      首先让我们检查数据库上的 CommPortIdentifier.class。

      作为 SYS: 从 dba_objects 中选择对象名称、状态 WHERE object_type like '%JAVA%' and dbms_java.longname(object_name) like '% CommPortIdentifier%';

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

      【讨论】:

        猜你喜欢
        • 2014-12-18
        • 1970-01-01
        • 2013-01-17
        • 1970-01-01
        • 1970-01-01
        • 2011-09-06
        • 2013-09-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多