Home » Developer & Programmer » JDeveloper, Java & XML » Need Help call Java Programm from PLSQL (merged) (JDK1.6.0_45)
Need Help call Java Programm from PLSQL (merged) [message #671038] Sun, 12 August 2018 02:34 Go to next message
MUKESH_ALTEC
Messages: 3
Registered: August 2018
Junior Member
HI all experts,

I have a Java Program which shows the List of Ports available in my system.

This program running fine at Command Prompt. But Now i want to use this Java program through PL/SQL.

But i am facing error as attached.

Spend Lot of time But can't Success.

Below is my Java Program.

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


  • Attachment: Error.jpg
    (Size: 128.92KB, Downloaded 3340 times)
Need Help call Java Programm from PLSQL [message #671069 is a reply to message #671038] Mon, 13 August 2018 23:41 Go to previous messageGo to next message
MUKESH_ALTEC
Messages: 3
Registered: August 2018
Junior Member
Dear All,

I have a Java Program which shows the List of Ports available in my system.

This program running fine at Command Prompt. But Now i want to use this Java program through PL/SQL.

I have Successfully Loaded Java Source and Java Class in Oracle.
Both Java Source and Java Class Status showing Valid in User_Obejcts Table.
But Unable to Call this from PLSQl

Spend Lot of time But can't Success.

Here is My PlSQL programm

CREATE OR REPLACE procedure TestPorts_PROC
AS LANGUAGE JAVA
NAME 'TestPorts.main(java.lang.String[])';

Error Showing

"exec TestPorts_PROC;
BEGIN TestPorts_PROC; END;

*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.NullPointerException: name can't be null
ORA-06512: at "HR1.TESTPORTS_PROC", line 1
ORA-06512: at line 1
"

Below is my Java Program.

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

[Updated on: Tue, 14 August 2018 00:08]

Report message to a moderator

Re: Need Help call Java Programm from PLSQL [message #671084 is a reply to message #671069] Wed, 15 August 2018 05:02 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9077
Registered: November 2002
Location: California, USA
Senior Member
Please try the following from SQL*Plus, inserting your java code where indicated:

create or replace and compile java source named "TestPorts"
as
... put the java code that you posted here
/
show errors

Check whether this compiles without error, then:

CREATE OR REPLACE procedure TestPorts_PROC
AS LANGUAGE JAVA
NAME 'TestPorts.main(java.lang.String[])';
/
show errors

and see if that compiles without error.


Re: Need Help call Java Programm from PLSQL [message #671085 is a reply to message #671084] Wed, 15 August 2018 05:12 Go to previous messageGo to next message
MUKESH_ALTEC
Messages: 3
Registered: August 2018
Junior Member
yes Done the same as you suggested but still getting the issue.

SQL> create or replace and compile java source named "TestPorts"
2 as
3 import javax.comm.*;
4 import java.util.*;
5 /** List all the ports available on the local machine. **/
6 public class TestPorts
7 {
8 public static void main (String args[])
9 {
10
11 Enumeration port_list = CommPortIdentifier.getPortIdentifiers();
12
13 while (port_list.hasMoreElements())
14 {
15 CommPortIdentifier port_id = (CommPortIdentifier)port_list.nextElement();
16
17 if (port_id.getPortType() == CommPortIdentifier.PORT_SERIAL)
18 {
19 System.out.println ("Serial port: " + port_id.getName());
20 }
21 else if (port_id.getPortType() == CommPortIdentifier.PORT_PARALLEL)
22 {
23 System.out.println ("Parallel port: " + port_id.getName());
24 }
25 else
26 System.out.println ("Other port: " + port_id.getName());
27 }
28 } // main
29 } // class PortList
30 /

Java created.

SQL> show error
No errors.
SQL> CREATE OR REPLACE procedure TestPorts_PROC
2 AS LANGUAGE JAVA
3 NAME 'TestPorts.main(java.lang.String[])';
4 /

Procedure created.

SQL> show error
No errors.
SQL> exec TestPorts_PROC;
BEGIN TestPorts_PROC; END;

*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.NullPointerException: name can't be null
ORA-06512: at "HR1.TESTPORTS_PROC", line 1
ORA-06512: at line 1


SQL>
Re: Need Help call Java Programm from PLSQL [message #671107 is a reply to message #671085] Wed, 15 August 2018 11:00 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Please read How to use [code] tags and make your code easier to read.
Indent the code and use code tags.
Also always post your Oracle version, with 4 decimals, as solution depends on it.

Re: Need Help call Java Programm from PLSQL [message #671108 is a reply to message #671085] Wed, 15 August 2018 11:03 Go to previous message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

SQL> CREATE OR REPLACE procedure TestPorts_PROC
2 AS LANGUAGE JAVA
3 NAME 'TestPorts.main(java.lang.String[])';
4 /

SQL> exec TestPorts_PROC;
BEGIN TestPorts_PROC; END;

*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.NullPointerException: name can't be null
ORA-06512: at "HR1.TESTPORTS_PROC", line 1
ORA-06512: at line 1

 main (String args[])

You call the procedure with no parameters when Java one takes an array, so the error, the PL/SQL procedure should has the same or equivalent parameters than the Java one.

Previous Topic: Oracle Retail v16 seeded customization - anyone pulled it off?
Next Topic: Chat Box Implementation
Goto Forum:
  


Current Time: Thu Mar 28 18:04:50 CDT 2024