Calling Java function from pl/sql [message #658330] |
Fri, 09 December 2016 10:30 |
|
dineshkumar18
Messages: 28 Registered: September 2016
|
Junior Member |
|
|
Below is the Java query which am using
<Code>
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class EncryptPdf
{
String owner = "PASS2";
String user = "PASS1";
public static final String DEST = "/SANVOL/DW_REPORTS/REPORTS/CRDB_Statements/4010390898001_e.pdf";
public static final String SRC = "/SANVOL/DW_REPORTS/REPORTS/CRDB_Statements/4010390898001.pdf";
public static void main(String[] args)
throws IOException, DocumentException
{
File file = new File("/SANVOL/DW_REPORTS/REPORTS/CRDB_Statements/4010390898001.pdf");
file.getParentFile().mkdirs();
new EncryptPdf().manipulatePdf("/SANVOL/DW_REPORTS/REPORTS/CRDB_Statements/4010390898001.pdf", "/SANVOL/DW_REPORTS/REPORTS/CRDB_Statements/4010390898001_e.pdf");
}
public void manipulatePdf(String src, String dest)
throws IOException, DocumentException
{
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
stamper.setEncryption(this.user.getBytes(), this.owner.getBytes(),
2052, 10);
stamper.close();
reader.close();
}
}
</Code>
Oracle procedure which am using:
<Code>
create or replace
PROCEDURE PR_encryptpdf (src in varchar2,dest in varchar2)
AS LANGUAGE JAVA
NAME 'EncryptPdf.manipulatePdf(java.lang.String ,java.lang.String)';
</code>
am not able to call the function successfully.it is showing class "manipulatePdf" is not found in class EncryptPdf
Please assist
|
|
|
|
|
|
|
|
|
|
|
|
Re: Calling Java function from pl/sql [message #658343 is a reply to message #658342] |
Fri, 09 December 2016 12:13 |
|
dineshkumar18
Messages: 28 Registered: September 2016
|
Junior Member |
|
|
Correct me as i have done few things:
Creating the java code as below and its successfully getting created:
create or replace and resolve java source named encryptpdf as
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class EncryptPdf
{
public static void manipulatePdf(String src, String dest , String USER_PASSWORD , String OWNER_PASSWORD ) throws IOException {
try
{
PdfReader pdfReader = new PdfReader(src);
PdfStamper pdfStamper = new PdfStamper(pdfReader,new FileOutputStream(dest));
pdfStamper.setEncryption(USER_PASSWORD.getBytes(),OWNER_PASSWORD.getBytes(),2052,10);
pdfStamper.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
}
Creating the oracle procedure to call the above created java function:
create or replace
PROCEDURE PR_encryptpdf_1 (src in varchar2,dest in varchar2,user_pwd in varchar2,owner_pwd in varchar2)
AS LANGUAGE JAVA
NAME 'EncryptPdf.manipulatePdf(java.lang.String ,java.lang.String ,java.lang.String ,java.lang.String)';
when i run the procedure am getting the below error:
ORA-29532: Java call terminated by uncaught Java exception: java.lang.NoClassDefFoundError: !!!ERROR!!! generated by genmissing
ORA-06512: at "CRDB.PR_ENCRYPTPDF_1", line 1
ORA-06512: at line 12
|
|
|
|
Re: Calling Java function from pl/sql [message #658345 is a reply to message #658343] |
Fri, 09 December 2016 12:20 |
|
Michel Cadot
Messages: 68686 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
SQL> create or replace and resolve java source named encryptpdf as
2
3 import com.itextpdf.text.pdf.PdfReader;
4 import com.itextpdf.text.pdf.PdfStamper;
5 import java.io.FileNotFoundException;
6 import java.io.FileOutputStream;
7 import java.io.IOException;
8
9
10 public class EncryptPdf
11 {
12
13 public static void manipulatePdf(String src, String dest , String USER_PASSWORD , String OWNER_PASSWORD ) throws IOException {
14 try
15 {
16 PdfReader pdfReader = new PdfReader(src);
17 PdfStamper pdfStamper = new PdfStamper(pdfReader,new FileOutputStream(dest));
18 pdfStamper.setEncryption(USER_PASSWORD.getBytes(),OWNER_PASSWORD.getBytes(),2052,10);
19 pdfStamper.close();
20 }
21 catch (FileNotFoundException e)
22 {
23 e.printStackTrace();
24 }
25
26 }
27 }
28 /
Warning: Java created with compilation errors.
SQL> sho err
Errors for JAVA SOURCE "ENCRYPTPDF":
LINE/COL ERROR
-------- -------------------------------------------------------------------------------------
0/0 ENCRYPTPDF:1: cannot find symbol
0/0 6 errors
0/0 location: package com.itextpdf.text.pdf
0/0 import com.itextpdf.text.pdf.PdfReader;
0/0 ^
0/0 ENCRYPTPDF:2: cannot find symbol
0/0 symbol : class PdfStamper
0/0 location: package com.itextpdf.text.pdf
0/0 import com.itextpdf.text.pdf.PdfStamper;
0/0 ^
0/0 ENCRYPTPDF:14: cannot find symbol
0/0 symbol : class PdfReader
0/0 location: class EncryptPdf
0/0 PdfReader pdfReader = new PdfReader(src);
0/0 ^
0/0 ENCRYPTPDF:14: cannot find symbol
0/0 symbol : class PdfReader
0/0 location: class EncryptPdf
0/0 PdfReader pdfReader = new PdfReader(src);
0/0 ^
0/0 ENCRYPTPDF:15: cannot find symbol
0/0 symbol : class PdfStamper
0/0 location: class EncryptPdf
0/0 PdfStamper pdfStamper = new PdfStamper(pdfReader,new FileOutputStream(dest));
0/0 ^
0/0 ENCRYPTPDF:15: cannot find symbol
0/0 symbol : class PdfStamper
0/0 location: class EncryptPdf
0/0 PdfStamper pdfStamper = new PdfStamper(pdfReader,new FileOutputStream(dest));
0/0 ^
0/0 symbol : class PdfReader
|
|
|
|
|
Re: Calling Java function from pl/sql [message #658349 is a reply to message #658347] |
Fri, 09 December 2016 12:42 |
|
dineshkumar18
Messages: 28 Registered: September 2016
|
Junior Member |
|
|
create or replace
PROCEDURE PR_encryptpdf_1 (src in varchar2,dest in varchar2,user_pwd in varchar2,owner_pwd in varchar2)
AS LANGUAGE JAVA
NAME 'EncryptPdf.manipulatePdf(java.lang.String ,java.lang.String ,java.lang.String ,java.lang.String)';
once that java function has been created , we need to create the above stored proc and run the stored proc by using the below:
DECLARE
SRC VARCHAR2(2000);
DEST VARCHAR2(2000);
USER_PWD VARCHAR2(200);
OWNER_PWD VARCHAR2(200);
BEGIN
SRC := '/SANVOL/DW_REPORTS/REPORTS/CRDB_Statements/4010390898001.pdf';
DEST := '/SANVOL/DW_REPORTS/REPORTS/CRDB_Statements/4010390898001_u.pdf';
USER_PWD := 'test';
OWNER_PWD := 'kill';
PR_ENCRYPTPDF_1(
SRC => SRC,
DEST => DEST,
USER_PWD => USER_PWD,
OWNER_PWD => OWNER_PWD
);
END;
SRC := '/SANVOL/DW_REPORTS/REPORTS/CRDB_Statements/4010390898001.pdf'; -- refers to a file in a database path
DEST := '/SANVOL/DW_REPORTS/REPORTS/CRDB_Statements/4010390898001_u.pdf'; -- creates the encryped file and this is the requirement and am facing the error while calling the java function.
Thanks Michael for helping this much
|
|
|
|
|
|
|
|
|
|
|
|
|
|