developers

    Forum Stats

  • 3,873,973 Users
  • 2,266,656 Discussions
  • 7,911,679 Comments

Discussions

Error While Execute Java Code From Database

Sameh M. Sewilam
Sameh M. Sewilam Member Posts: 96 Blue Ribbon

Hi All


I have a 19c Oracle Database with the following specifications


SELECT * from v$version;

Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production


SELECT dbms_java.get_jdk_version JDK_Version FROM dual;

1.8.0_201


OS : Windows Server 2016

Installed Java jdk1.7.0_80 and jdk-9.0.1



I have Created A java Code with eclipse to print reports and merge the printed reports to one PDF.

I tested it and it works fine. Then i loaded it to Database with all dependence using loadjava

The Class created successfully without any compilation error and its status is VALID


create or replace and compile java source named MergePDFJava As


import oracle.aurora.rdbms.ClassHandle;

import oracle.aurora.rdbms.Schema;

import oracle.aurora.rdbms.DbmsJava;

import java.io.File;

import java.io.IOException;

import java.nio.file.Files;

import java.util.Base64;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import net.sf.jasperreports.engine.JRException;

import net.sf.jasperreports.engine.JasperCompileManager;

import net.sf.jasperreports.engine.JasperFillManager;

import net.sf.jasperreports.engine.JasperPrint;

import net.sf.jasperreports.engine.JasperReport;

import net.sf.jasperreports.engine.export.JRPdfExporter;

import net.sf.jasperreports.export.SimpleExporterInput;

import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;

import net.sf.jasperreports.export.SimplePdfExporterConfiguration;




public class MergePDFJava {


   public static String combineReports (String file_name ,String report_name,String visit_id,String pid) throws ClassNotFoundException, SQLException, JRException, IOException {

      String dir = "E:/printedresults/";



      List<JasperPrint> jasperPrintList = new ArrayList<>();


      Connection conn = getOracleConnection();

       String[] report_name_array = report_name.split(",", 100);

       String[] visitid_array = visit_id.split(",", 100);

       String[] pid_array = pid.split(",", 100);

           for (int i = 0; i < report_name_array.length; i++) {

                   String Report = dir+report_name_array[i];

                   Map<String, Object> parameters = new HashMap<>();

                   parameters.put("PVisitID", visitid_array[i]);

                   parameters.put("PID", pid_array[i]);

                   JasperReport jr = JasperCompileManager.compileReport(Report);

                   JasperPrint jp1 = JasperFillManager.fillReport(jr, parameters,conn);

                   jasperPrintList.add(jp1);


    }



      JRPdfExporter exporter = new JRPdfExporter();

      exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));

      exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(dir +file_name +".pdf"));

      SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();

      exporter.setConfiguration(configuration);

      exporter.exportReport();

      return "Printing...";


   }

   public static Connection getOracleConnection()

           throws ClassNotFoundException, SQLException {

       String hostName = "server";

       String sid = "orclpdb";

       String userName = "username";

       String password = "password";


       return getOracleConnection(hostName, sid, userName, password);

   }


   public static Connection getOracleConnection(String hostName, String sid,

           String userName, String password) throws ClassNotFoundException,

           SQLException {


       Class.forName("oracle.jdbc.driver.OracleDriver");



       String connectionURL = "jdbc:oracle:thin:@" + hostName + ":1521/" + sid;


       Connection conn = DriverManager.getConnection(connectionURL, userName,

               password);

       return conn;

   }

   }


Then I created a Function as

create or replace FUNCTION portal_print_result (

   file_name VARCHAR2,

   report_name VARCHAR2,

   visit_id    VARCHAR2,

   pid        VARCHAR2

) RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'MergePDFJava.combineReports( java.lang.String, java.lang.String, java.lang.String, java.lang.String ) return java.lang.String ';

and it's created successfully without errors


and while execution i got the below error

DECLARE

   x CLOB;

BEGIN

   x := portal_print_result(

                               '45896',

                               'Dental_Lab_Order.jasper,Dental_Lab_Order.jasper',

                               '8615,8572',

                               '48,21'

        );

END;


ORA-29532: Java call terminated by uncaught Java exception: java.lang.NoClassDefFoundError

ORA-06512: at "PORTAL_PRINT_RESULT", line 1

ORA-06512: at line 4

29532. 00000 - "Java call terminated by uncaught Java exception: %s"

*Cause:   A Java exception or error was signaled and could not be

          resolved by the Java code.

*Action:  Modify Java code, if this behavior is not intended.


Consider that user has all needed privilege

BEGIN

   dbms_java.grant_permission('USER','SYS:java.io.FilePermission','<<ALL FILES>>','read,write,execute,delete');

   dbms_java.grant_permission('USER','SYS:java.lang.RuntimePermission','readFileDescriptor','');

   dbms_java.grant_permission('USER','SYS:java.lang.RuntimePermission','writeFileDescriptor','');

   dbms_java.grant_permission('USER','java.util.PropertyPermission','*','read');

   dbms_java.grant_permission( 'USER', 'SYS:java.lang.RuntimePermission', 'getClassLoader', ' ' );

   dbms_java.grant_permission( 'USER', 'SYS:oracle.aurora.security.JServerPermission', 'Verifier', ' ' );

   dbms_java.grant_permission( 'USER', 'SYS:java.lang.RuntimePermission', 'accessClassInPackage.sun.util.calendar', ' ' ) ;

   dbms_java.grant_permission( 'USER', 'java.net.SocketPermission', '*', 'connect,resolve' );

   dbms_java.grant_permission( 'USER', 'SYS:java.lang.RuntimePermission', 'createClassLoader', ' ');

   COMMIT;

END;

/



Can anyone support in the mentioned errors

Thanks in advance

Answers

  • User_H3J7U
    User_H3J7U Member Posts: 1,062 Gold Trophy

    Enable the redirection of java output: dbms_output.enable()/set output + dbms_java.set_output()

  • Sameh M. Sewilam
    Sameh M. Sewilam Member Posts: 96 Blue Ribbon

    Hi User_H3J7U

    Thank you for your replay

    I got the following error details

    Mar 29, 2022 12:20:23 PM net.sf.jasperreports.extensions.DefaultExtensionsRegistry loadRegistries

    SEVERE: Error instantiating extensions registry for data.adapter.services from jserver:/resource/schema/USER/jasperreports_extension.properties

    net.sf.jasperreports.engine.JRRuntimeException: Could not load class net.sf.jasperreports.data.DefaultDataAdapterServiceExtensionsRegistryFactory.

       at net.sf.jasperreports.engine.util.ClassUtils.instantiateClass(ClassUtils.java)

       at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.instantiateRegistry(DefaultExtensionsRegistry.java)

       at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:274)

       at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java)

       at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getRegistries(DefaultExtensionsRegistry.java)

       at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java)

       at net.sf.jasperreports.engine.DefaultJasperReportsContext.getExtensions(DefaultJasperReportsContext.java)

       at net.sf.jasperreports.engine.component.ComponentsEnvironment.findBundles(ComponentsEnvironment.java)

       at net.sf.jasperreports.engine.component.ComponentsEnvironment.getCachedBundles(ComponentsEnvironment.java)

       at net.sf.jasperreports.engine.component.ComponentsEnvironment.getBundles(ComponentsEnvironment.java)

       at net.sf.jasperreports.engine.xml.JRReportSaxParserFactory.getSchemaLocations(JRReportSaxParserFactory.java:103)

       at net.sf.jasperreports.engine.xml.BaseSaxParserFactory.configureParser(BaseSaxParserFactory.java:163)

       at net.sf.jasperreports.engine.xml.BaseSaxParserFactory.createParser(BaseSaxParserFactory.java:118)

       at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createParser(JRXmlDigesterFactory.java:1564)

       at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(JRXmlDigesterFactory.java:1542)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:256)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:212)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:187)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:178)

       at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:289)

       at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:576)

       at MergePDFJava.combineReports(MERGEPDFJAVA:40)

    Caused by: java.lang.ClassNotFoundException: net/sf/jasperreports/data/DefaultDataAdapterServiceExtensionsRegistryFactory

       at java.lang.Class.forName0(Native Method)

       at java.lang.Class.forName(Class.java)

       at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java)

       at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java)

       ... 22 more


    Exception in thread "Root Thread" net.sf.jasperreports.engine.JRException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:299)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:278)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:267)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:212)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:187)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:178)

       at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:289)

       at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:576)

       at MergePDFJava.combineReports(MERGEPDFJAVA:40)

    Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

       at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java)

       at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java)

       at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java)

       at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapacity(XMLEntityScanner.java)

       at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(XMLEntityScanner.java)

       at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java)

       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:806)

       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)

       at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)

       at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)

       at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)

       at org.apache.commons.digester.Digester.parse(Digester.java:1892)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:291)

       ... 8 more

    Exception in thread "Root Thread" net.sf.jasperreports.engine.JRException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:299)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:278)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:267)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:212)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:187)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:178)

       at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:289)

       at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:576)

       at MergePDFJava.combineReports(MERGEPDFJAVA:40)

    Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

       at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java)

       at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java)

       at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java)

       at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapacity(XMLEntityScanner.java)

       at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(XMLEntityScanner.java)

       at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java)

       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:806)

       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)

       at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)

       at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)

       at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)

       at org.apache.commons.digester.Digester.parse(Digester.java:1892)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:291)

       ... 8 more

  • Sameh M. Sewilam
    Sameh M. Sewilam Member Posts: 96 Blue Ribbon

    I seems that loaded jars not working properly as it was in classpath as extenal jars.

    I load some versions of old jars and now the latest error is

    Exception in thread "Root Thread" net.sf.jasperreports.engine.JRException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:305)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:284)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:273)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:218)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:193)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:184)

       at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:285)

       at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:572)

       at MergePDFJava.combineReports(MERGEPDFJAVA:40)

    Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

       at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java)

       at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java)

       at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java)

       at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapacity(XMLEntityScanner.java)

       at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(XMLEntityScanner.java)

       at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java)

       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:806)

       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)

       at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)

       at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)

       at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)

       at org.apache.commons.digester.Digester.parse(Digester.java:1892)

       at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:297)

       ... 8 more

  • User_F1XQZ
    User_F1XQZ Member Posts: 1 Green Ribbon
    edited May 14, 2022 12:00PM

    wanna know what languages you need to know in 2022?

    check this out: Best Programming Languages To Learn In 2022

developers