I am using java methods in PL/SQL and recently I have stumbled upon this error :
An error was encounterd performing the request operation:
ORA-29548: Release of Java system classes in database (12.1.0.2.171017
1.6) does not match that of the oracle executable (12.1.0.2.180116 1.6)
29548. 00000 = "Java system class reported" %s"
What should I do to make it work?
Make sure the java version you use to compile and the version installed in ORACLE both are same.
select dbms_java.get_ojvm_property ('java.version')
from dual
Although, you can let Oracle do compile the source code directly.
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "Azam/Azam_Test" as package Azam;
import java.lang.*;
public class Azam_Test {
public static String Azam_Test_Print(String testString) {
System.out.println(testString);
return testString;
}
}
Related
I'm using the Groovy Spreadsheet Builder within one of my Grails projects to export some data as Excel file.
Everything works great until I create a runnable jar (using gradle assemble) and use this.
I'm using the builder within a service like this:
class ExcelService {
...
void export(OutputStream outputStream) {
...
PoiSpreadsheetBuilder.create(outputStream).build {
apply ExcelStylesheet
...
}
}
...
}
When I try to export my data from the app started using the generated jar I will get the following MissingMethodException:
groovy.lang.MissingMethodException: No signature of method: my.package.ExcelService.apply() is applicable for argument types: (java.lang.Class)
The (Java) interface of SpreadsheetBuilder looks like this:
public interface SpreadsheetBuilder {
void build(#DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = WorkbookDefinition.class) #ClosureParams(value = FromString.class, options = "builders.dsl.spreadsheet.builder.api.WorkbookDefinition") Configurer<WorkbookDefinition> workbookDefinition);
}
While debugging the execution of the code and the jar I found the difference while stepping through invokeMethod() of ClosureMetaClass.
When closure.getResolveStrategy(); in the working version is called Closure.DELEGATE_FIRST will be returned. Debugging the jar, the result will be 0 so that the MissingMethodException will be thrown later due to the wrong resolve strategy.
For now I have no idea how to solve this problem.
What is/could be the reason for this behavior?
What can I do to solve this issue?
I'm using Grails 3.3.8 with Java OpenJDK 1.8.0_192.
If you don't need to support JDK 7, you could upgrade to Groovy Spreadsheet Builder 2.0.0.RC1 which is only JDK 8 compatible but appears to solve the problem.
#ClosureParams and #DelegatesTo are applicable to parameters of type groovy.lang.Closure. In this case, you have applied it to Configurer<WorkbookDefinition>.
I have an Oracle 12 database and I'm trying to load a Java function so that it can be called from PL/SQL.
I've written a NetBeans project to test my function and it works fine.
However, inside Oracle, it cannot compile.
One factor is that it references a library of about 75 jar files.
I loaded these jars into the database earlier using
loadjava -u ......... *.jar -jarasresource
(These are the same jars that are part of the NetBeans library.)
The source was loaded into the database using loadjava:
loadjava -u ......... -r -v -genmissing PictureGenerator.java
The error messages mention the classes in the import statements.
StandardCharsets is part of the JDK, isn't it?
The other imported classes are included in the jar files I loaded.
Please tell me what to do to get my class to resolve within Oracle.
Here's the source:
package gov.nlm.structuredepictor;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import chemaxon.formats.MolExporter;
import chemaxon.formats.MolImporter;
import chemaxon.struc.Molecule;
public class PictureGenerator
{
public static byte[] getPngForMol(String molString, String sbFormat)
{
MolImporter mi = null;
try
{
ByteArrayInputStream inStream = new ByteArrayInputStream(molString.getBytes(StandardCharsets.UTF_8));
if (inStream == null)
{
System.err.print("Error creating ByteArrayInputStream");
return null;
}
mi = new MolImporter(inStream);
Molecule mol = mi.read();
mi.close();
byte[] b = MolExporter.exportToBinFormat(mol, sbFormat);
return b;
} catch (Exception ex1)
{
System.err.println("Error creeating MolImporter: " + ex1.getMessage());
//Logger.getLogger(PictureGenerator.class.getName()).log(Level.SEVERE, null, ex1);
}
return null;
}
}
Thanks for the suggestion about the JDK version! I changed the DB to use JDK 7 and was able to compile without errors. The next step was to declare the PL/SQL function
create or replace function getPngForMol(molString varchar2, sbFormat varchar2) return raw
as LANGUAGE JAVA
Name 'gov.nlm.structuredepictor.PictureGenerator.getPngForMol(java.lang.String, java.lang.String)
return byte[]';
This compiled without error. However, at runtime, I get this error:
Error report -
ORA-29532: Java call terminated by uncaught Java exception: java.lang.NoClassDefFoundError
ORA-06512: at "CHEM.GETPNGFORMOL", line 1
ORA-06512: at line 11
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.
Does this suggest anything?
I have looked at all the other stuff, mine is a compatibility issue I think, or PATH maybe. I have a bunch of classes I've been using since about 2008 and now the java command and the javac command can't find the classes even though they are in the same directory/folder. I have C:\Program Files\Java\jdk1.6.0_25\bin in the Path variable, but nothing in the Classpath. I normally have the compiled classes in the same folder with the java I'm compiling. I've been doing the same thing for 5 years! I have recompiled the lowest level class which is called WotifCat01. The compiler comes back with
WotifCat00.java:27:cannot find symbol
Symbol : WotifCat01
import java.io.*;
/** Find/replace program **/
class WotifCat00
{
private static int cnt;
private static String[][] filnamStrg={ {"Data/reftfile.txt","Data/AccumData/allreftfile.txt","","",""},
{"Data/reft1file.txt","Data/AccumData/allreft1file.txt","","",""},
{"Data/reft2file.txt","Data/AccumData/allreft2file.txt","","",""},
{"Data/reft3file.txt","Data/AccumData/allreft3file.txt","","",""},
{"Data/reft4file.txt","Data/AccumData/allreft4file.txt","","",""},
{"Data/work1file.txt","Data/AccumData/alltextsrc.txt","","",""},
{"","","","",""} };
private static String[] args1={"","","","",""};
public static void main(String[] args) {
while (filnamStrg[cnt][0] != "") {
args1[0] = filnamStrg[cnt][0];
args1[1] = filnamStrg[cnt][1];
WotifCat01 wotifCat01 = new WotifCat01();
wotifCat01.main(args1);
cnt++;
}
}
}
I've used this setup for a while and it worked fine on my laptop till now with Windows 7. I suspect something I've installed has overwritten something. This has to be really simple but I can't see it. I've removed jdk1.7.0_25 back to 1.6 but no change.
I backed up the classpath and deleted it. Now works fine. It contained IBM DB2 paths. DB2 I had installed in 2011 so discounted it, but it did have java paths in it so it must have overrode the path. I am not sure how DB2 managed to do so 2 years after install, I may have inadvertently activated something. Thanks for your input.
Neil Mc
I am having trouble using Create Function Command for Derby Database.
To start with I tried
CREATE FUNCTION TO_DEGREES(RADIANS DOUBLE) RETURNS DOUBLE
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'java.lang.Math.toDegrees'
and then
SELECT TO_DEGREES(3.142), BILLNO FROM SALEBILL
This works absolutely fine.
Now I tried making my own function like this :
package SQLUtils;
public final class TestClass
{
public TestClass()
{
}
public static int addNos(int val1, int val2)
{
return(val1+val2);
}
}
followed by
CREATE FUNCTION addno(no1 int, no2 int) RETURNS int
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'SQLUtils.TestClass.addNos'
and then
SELECT addno(3,4), BILLNO FROM SALEBILL
This gives an Exception
Error code -1, SQL state 42X51: The class 'SQLUtils.TestClass' does not exist or is inaccessible. This can happen if the class is not public.
Error code 99999, SQL state XJ001: Java exception: 'SQLUtils.TestClass: java.lang.ClassNotFoundException'.
Line 6, column 1
I have made a jar file of the project containing the above Class. I may be wrong but the conclusion that I can draw from this is that this jar file needs to be in some classpath. But in which classpath and how to add it to a classpath, I am not able to understand.
I tried copying the jar file to jdk\lib folder, jre\lib folder, jdk\jre\lib folder but to no avail.
Can someone please point me in the right direction ?
I am using NetBeans IDE 7.1.2, jdk 1.7.0_09, Derby version 10.8.1.2 in Network mode. The applications and data are on a Server. I access them from Netbeans installed on client computer.
public class HelloWorld{
public static void add(int a, int b){
System.out.println(a+b);
}
}
and I load it into oracle via
loadjava -user system/admin Helloworld.class
This words fine.
After that I write this procedure:
create or replace
PROCEDURE start_helloworld(a in number, b in number)
AS language java
name 'HelloWorld.add(int,int)';
I want to be able to call the procedure in PL/SQL:
exec start_helloworld(1,1);
but it gives the error I mentioned.
You can't do console output from Oracle java code, since it's running within the database. Perhaps if you passed in and in/out variable, assigned the output of your arithmetic assignment to the variable and output that in the calling PL/SQL block:
var mynum NUMBER
exec start_helloworld(1,1,:mynum);
print mynum;
You would of course need to modify your java and PL/SQL wrapper to add the new parameter:
public static void add(int a, int b, int c){
c = a+b;
}
and
create or replace
PROCEDURE start_helloworld(a in number, b in number, c in out number)
AS language java
name 'HelloWorld.add(int,int,int)';
I am not an Oracle expert by any means but I have hit this issue recently so I just wanted to comment. For some reason I can't just leave a comment, So here's my answer.
Comment:
When I get the Ora-29516 error, it comes with a reason description. Is there more to the error when you get it?
Answer:
If your Aurora Assertion error comes with the reason "Uncaught exception System error: java/lang/UnsupportedClassVersionError" =>
I get this error when the version of Java I used to compile the class file isn't the same as the version of Java in Oracle (1.5.0 in 11g). To be sure you match perfectly, let Oracle compile the class for you. You'll get two benefits: 1) You will be sure the Java version matches exactly. 2) You'll have the source code loaded as a database "JAVA SOURCE" object for future reference. For security purposes, you may want to lock it down.
loadjava -user scott/tiger -resolve HelloWorld.java
By using the source file with the resolve option, Oracle will create the source object and compile the code for the class object. If you leave out the -resolve option, Oracle will create the source object and only compile it when it is called. I presume this may have good flexibility options but performance drawbacks.
This error occurs because incompatibility of different java versions in oracle and java compiler.
-> oracle version:
--TO CHECK JAVA VERSION IN ORACLE
SELECT dbms_java.get_ojvm_property(PROPSTRING=>'java.version') FROM dual;
FOLLOW THIS STEPS :
//java
class simple{
public static String world(){
return("Hello Java");
}
}
Insted of loading class Simple load your java directly,
STEP1 :
loadjava -user system/admin simple.java
STEP2:
then > create one procedure
CREATE OR REPLACE PROCEDURE PROC_DEMO as
language java
name 'simple.world()';
/
STEP3:
declare -- Parameter declaration
RESULT VARCHAR2(2000);
begin
-- Please customize initialization
-- Call the procedure/function
RESULT := FUNC_DEMO;
-- Print out the results
dbms_output.put_line( 'RESULT = ' || SUBSTR( RESULT, 1, 255));
end;