Speed test: PL/SQL vs. Java Stored Procedures
I performed tests on these two procedures:
===========================================
// Create a Statement
Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
// Query the table
ResultSet rset = stmt.executeQuery ("select SIFOB, SIFRA_GU from sezko");
while (rset.next ()) {
salary = rset.getInt(1);
rset.updateInt (1, salary + 1);
salary = rset.getInt(2);
rset.updateInt (2, salary + 1);
rset.updateRow();
} // while
conn.commit();
// Close the RseultSet
rset.close();
// Close the Statement
stmt.close();
===========================================
procedure updateTable is
cursor c_updateTable is select rowid, SIFOB, SIFRA_GU from sezko;
begin
for r_updateTable in c_updateTable loop
update sezko set SIFOB = SIFOB + 1, SIFRA_GU = SIFRA_GU + 1 where rowid = r_updateTable.rowid;
end loop;
commit;
end;
===========================================
First procedure is written in Java (as Java Stored procedure) and second is PL/SQL.
Java is about 10x slower than PL/SQL code.
Can you explain bad performance results?
thank you
Matic & Ales
Hi,
I suppose the problem is not with the connection object,but with make connection to the database for every executeupdate or executeupdaterow called .Similarly for fetching the data from the database you
can use the fetch size technique.Please check the 8.1.6 Java Developers guide for using this.
Update Batching(For Batch updates and commits)
Fetch Size(For Batch fetching)
Oracle Row Pre-Fetching
Regards
Anand
null
Similar Messages
-
Send byte array argeument from pl/sql to java stored procedure?
I have a java method that accepts an argument of type byte[].
I want to define a call specification so that it can invoked from a sql statement.
The Java Developer's Guide show how to map SQL data types to java types and classes, but it is unclear if I can map a SQL data type to an array.
Does anyone know which SQL type to use to map to a byte array?
I'm using Oracle 10.2, thus jvm 1.4.2.As soon as I posted this question, I saw the RAW to byte[] mapping listed in the documentation. How did I overlook it? Anyway, that what I needed.
-
Issue with sending mail through java stored procedure in Oracle
Hello
I am using Oracle 9i DB. I created a java stored procedure to send mail using the code given below. The java class works fine standalone. When its run from Java, mail is sent as desired. But when the java stored procedure is called from pl/sql "Must issue a STARTTLS command first" error is thrown. Please let me know if am missing something. Tried the same code in 11.2.0.2 DB and got the same error
Error:
javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. va6sm31201010igc.6
Code for creating java stored procedure: (T1 is the table created for debugging)
==================================================
create or replace and compile java source named "MailUtil1" AS
import java.util.Enumeration;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MailUtil1 {
public static void sendMailwithSTARTTLS(String host, //smtp.projectp.com
String from, //sender mail id
String fromPwd,//sender mail pwd
String port,//587
String to,//recepient email ids
String cc,
String subject,
String messageBody) {
try{
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "True"); // added this line
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", fromPwd);
props.put("mail.smtp.port", port);
props.put("mail.smtp.auth", "true");
#sql { insert into t1 (c1) values ('1'||:host)};
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
#sql { insert into t1 (c1) values ('2')};
InternetAddress[] toAddress = new InternetAddress[1];
// To get the array of addresses
for( int i=0; i < toAddress.length; i++ ) { // changed from a while loop
toAddress[i] = new InternetAddress(to);
//System.out.println(Message.RecipientType.TO);
for( int i=0; i < toAddress.length; i++) { // changed from a while loop
message.addRecipient(Message.RecipientType.TO, toAddress);
if (cc!=null) {
InternetAddress [] ccAddress = new InternetAddress[1];
for(int j=0;j<ccAddress.length;j++){
ccAddress[j] = new InternetAddress(cc);
for (int j=0;j<ccAddress.length;j++){
message.addRecipient(Message.RecipientType.CC, ccAddress[j]);
message.setSubject(subject);
message.setText(messageBody);
message.saveChanges();
#sql { insert into t1 (c1) values ('3')};
Enumeration en = message.getAllHeaderLines();
String token;
while(en.hasMoreElements()){
token ="E:"+en.nextElement().toString();
#sql { insert into t1 (c1) values (:token)};
token ="ConTyp:"+message.getContentType();
#sql { insert into t1 (c1) values (:token)};
token = "Encod:"+message.getEncoding();
#sql { insert into t1 (c1) values (:token)};
token = "Con:"+message.getContent();
#sql { insert into t1 (c1) values (:token)};
Transport transport = session.getTransport("smtp");
#sql { insert into t1 (c1) values ('3.1')};
transport.connect(host, from, fromPwd);
#sql { insert into t1 (c1) values ('3.2')};
transport.sendMessage(message, message.getAllRecipients());
#sql { insert into t1 (c1) values ('3.3')};
transport.close();
#sql { insert into t1 (c1) values ('4')};
catch(Exception e){
e.printStackTrace();
String ex= e.toString();
try{
#sql { insert into t1 (c1) values (:ex)};
catch(Exception e1)
Edited by: user12050615 on Jan 16, 2012 12:18 AMHello,
Thanks for the reply. Actually I have seen that post before creating this thread. I thought that I could make use of java mail to work around this problem. I created a java class that succesfully sends mail to SSL host. I tried to call this java class from pl-sql through java stored procedure. That did not work
So, is this not supported in Oracle ? Please note that I have tested this in both 9i and 11g , in both the versions I got the error. You can refer to the code in the above post.
Thanks
Srikanth
Edited by: user12050615 on Jan 16, 2012 12:17 AM -
Size limitation that can be passed to Java stored procedure
Hello!
I enjoy using Oracle8i these days. But I have some questions
about Java stored procedure. I want to pass the XML data to Java
stored procedure as IN parameter. But I got some errors when the
data size is long. Is there any limitation in the data size that
can be passed to Java stored procedure?
Would you please help me ?
This message is long, but would you please read my message?
Contents
1. Outline : I write what I want to do and the error message I
got
2. About the data size boundary: I write about the boundary
size. I found that it depend on which calling sequence I use.
3. The source code of the Java stored procedure
4. The source code of the Java code that call the Java stored
procedure
5. The call spec
6. Environment
1.Outline
I want to pass the XML data to Java stored procedure. But I got
some errors when the data size is long. The error message I got
is below.
[ Error messages and stack trace ]
java.sql.SQLException: ORA-01460: unimplemented or unreasonable
conversion reque
sted
java.sql.SQLException: ORA-01460: unimplemented or unreasonable
conversion reque
sted
at oracle.jdbc.ttc7.TTIoer.processError(Compiled Code)
at oracle.jdbc.ttc7.Oall7.receive(Compiled Code)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(Compiled Code)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch
(TTC7Protocol.java:721
at oracle.jdbc.driver.OracleStatement.doExecuteOther
(Compiled Code)
at oracle.jdbc.driver.OracleStatement.doExecuteWithBatch
(Compiled Code)
at oracle.jdbc.driver.OracleStatement.doExecute(Compiled
Code)
at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(Compiled
Code
at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate
(OraclePrepar
edStatement.java:256)
at oracle.jdbc.driver.OraclePreparedStatement.execute
(OraclePreparedStat
ement.java:273)
at javaSp.javaSpTestMain.sample_test
(javaSpTestMain.java:37)
at javaSp.javaSpTestMain.main(javaSpTestMain.java:72)
2. About the data size boundary
I don|ft know the boundary that I got errors exactly, but I
found that the boundary will be changed if I use |gprepareCall("
CALL insertData(?)");|h or |gprepareCall ("begin insertData
(?); end ;")|h.
When I use |gprepareCall(" CALL insertData(?)".
The data size 3931 byte --- No Error
The data size 4045 byte --- Error
Whne I use prepareCall ("begin insertData(?); end ;")
The data size 32612 byte --No Error
The data size 32692 byte --- Error
3. The source code of the Java stored procedure
public class javaSpBytesSample {
public javaSpBytesSample() {
public static int insertData( byte[] xmlDataBytes ) throws
SQLException{
int oraCode =0;
String xmlData = new String(xmlDataBytes);
try{
Connection l_connection; //Database Connection Object
//parse XML Data
dits_parser dp = new dits_parser(xmlData);
//Get data num
int datanum = dp.getElementNum("name");
//insesrt the data
PreparedStatement l_stmt;
for( int i = 0; i < datanum; i++ ){
l_stmt = l_connection.prepareStatement("INSERT INTO test
" +
"(LPID, NAME, SEX) " +
"values(?, ?, ?)");
l_stmt.setString(1,"LIPD_null");
l_stmt.setString(2,dp.getElemntValueByTagName("name",i));
l_stmt.setString(3,dp.getElemntValueByTagName("sex",i));
l_stmt.execute();
l_stmt.close(); //Close the Statement
l_stmt = l_connection.prepareStatement("COMMIT"); //
Commit the changes
l_stmt.execute();
l_stmt.close(); //Close the Statement l_stmt.execute
(); // Execute the Statement
catch(SQLException e ){
System.out.println(e.toString());
return(e.getErrorCode());
return(oraCode);
4. The source code of the Java code that call the Java stored
procedure
public static void sample_test(int num) {
//make data
Patient p = new Patient();
byte[] xmlData = p.generateXMLData(num);
try{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
Connection m_connection = DriverManager.getConnection
("jdbc:oracle:thin:@max:1521:test",
"testuser", "testuser");
CallableStatement l_stmt =
// m_connection.prepareCall(" CALL insertData(?)");
m_connection.prepareCall("begin insertData(?); end
l_stmt.setBytes(1,xmlData);
l_stmt.execute();
l_stmt.close();
System.out.println("SUCCESS to insert data");
catch(SQLException e ){
System.out.println( e.toString());
e.printStackTrace();
5. The call spec
CREATE OR REPLACE PROCEDURE insertData( xmlData IN LONG RAW)
AS
LANGUAGE JAVA NAME 'javaSp.javaSpBytesSample.insertData(byte[])';
6. Environment
OS: Windows NT 4.0 SP3
RDBMS: Oracle 8i Enterprise Edition Release 8.1.5.0.0 for
Windows NT
JDBC Driver: Oracle JDBC Drivers 8.1.5.0.0.
JVM: Java1.1.6_Borland ( The test program that call Java stored
procedure run on this Java VM)
nullIam passing an array of objects from Java to the C
file. The total size of data that Iam sending is
around 1GB. I have to load this data into the Shared
memory after getting it in my C file. Iam working on
HP-UX (64-bit). Everything works fine for around 400MB
of data. When I try to send around 500MB of data, the
disk utilization becomes 100%, so does my memory
utilization and I get a "Not enough space" when I try
to access shared memory. I have allocated nearly 2.5GB
in my SHMMAX variable. Also, I have around 45GB of
disk free. The JVM heap size is also at 2048MB. Where did you get the 400/500 number from? Is that the size of the file?
What do you do with the data? Are you doing nothing but copying it byte for byte into shared memory?
If yes then a simple test is to write a C application that does the same thing. If it has problems then it means you have an environment problem.
If no then you are probably increasing the size of the data by creating a structure to hold it. How much overhead does that add to the size of the data? -
Issue with XSL transformation in Java Stored Procedure
Hi,
Am having issue applying XSL transformation in Java Stored procedure. I have loaded the java class as well as .XSL files through loadjava uility and their status in DB is VALID.
Below is the code in the java stored procedure:
public static String tranform(String strInputXML ){
URL url = ClassLoader.getSystemClassLoader().getResource(first.xsl);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new ByteArrayInputStream (strInputXML.getBytes("UTF-8")));
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource stylesource = new StreamSource(url.openStream());
Transformer transformer = tFactory.newTransformer(stylesource);
When I run this procedure, am getting following errors:
{color:#ff0000}*ERROR: 'No such file or directory'*
FATAL ERROR: 'Could not compile stylesheet'{color}
My first.xsl file has reference to other excel file (Ex: <xsl:include href="second.xsl"/>) which seems to be causing this error. When I remove the reference, procedure is working fine.
Pls let me know how to resolve this and read the .XSL file with references.
Thanks,Hello,
Thanks for the reply. Actually I have seen that post before creating this thread. I thought that I could make use of java mail to work around this problem. I created a java class that succesfully sends mail to SSL host. I tried to call this java class from pl-sql through java stored procedure. That did not work
So, is this not supported in Oracle ? Please note that I have tested this in both 9i and 11g , in both the versions I got the error. You can refer to the code in the above post.
Thanks
Srikanth
Edited by: user12050615 on Jan 16, 2012 12:17 AM -
Java stored procedure vs. PL-SQL vs. external java program
Hi,
I'm using a stored procedure for running a query and a few consequent updates. Currently I'm using Java stored procedure for that, which was my choice for simplicity on one hand, and running with the DB on the other.
In my tests, strangely enough it came out that running as java stored procedure was 3-4 times slower than running as a java program outside the database. I don't know how to explain this, and I wonder if switching to PL/SQL will improve the performance of the code.
Any experiences? recommendations?
Thanks,
DawgIn my tests, strangely enough it came out that running as java stored procedure was 3-4 times slower than running as a java program outside the database. I don't know how to explain this, and I wonder if switching to PL/SQL will improve the performance of the code.This isn't strange at all. See: Oracle's JVM (Aurora) is an independent Java Virtual Machine implementation, in accordance to specification. It implements all necessary parts of it (I think so). When you use an external JVM (I assume it's Sun's HotSpot JVM) you use completely different product. It is implemented in different way, it has many different code parts.
One of the biggest differences between Oracle's JVM and Sun's JVM is [Just-in-Time compiler|http://en.wikipedia.org/wiki/Just-in-time_compilation]. Oracle has implemented it only in the 11g version of database, i.e. 2 years ago, while Sun performed it back in 2000 and continues to improve it for the last 9 years. That would explain obvious differences between Java program inside and outside the DB: they are executed in absolutely different worlds. Diffs could be up to 10x times or more - that's not unusual.
If you are on 10g and want to compare performance of stored Java procedure vs external program, then you might use additional command-line instruction for external program to disable JIT:
-XintPS. I wouldn't use Java for your task - that's a total overkill. Use simple SP instead. -
Calling the Java Method in PL/SQL Java Stored procedure errors out
Hi,
I could not find a suitable thread to post my PL/SQL question so iam posting it here.........
I have written a java class by name XYZ which has a method ABC for which there are 9 arguements being passed and its a VOID method.
This java class has been loaded into ORACLE using DBMS_JAVA.LOADJAVA pkg, Now this class is being called in the oracle as a JAVA Stored procedure...... When ever im trying to call the procedure it throws the following error
ORA-29531: no method
*Cause: An attempt was made to execute a non-existent method in a
Java class.
*Action: Adjust the call or create the specified method.
The code snippet as follows
JAVA CODE:
Class xyz
public static void Abc (String hostName,
int port,
String serviceURL,
String soapAction,
int timeOut,
String wsUser,
String wsPasWd,
String keyStore,
String keyStorePasWd)
//method implementation
JAVA STORED PROCEDURE:
create OR REPLACE procedure ABC_JAVA_SP_CALL
(p_hostname in varchar2, p_port in number, p_serviceurl in varchar2, p_soapaction in varchar2, p_timeout in number, p_wsuser in varchar2, p_wspasswd in varchar2, p_ks_path in varchar2, p_ks_passwd in varchar2)
as
language java
name 'xyz.Abc(java.lang.String, int, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String)';
When i try to call
declare
p_hostname varchar2(100);
p_port number;
p_serviceurl varchar2(100);
p_soapaction varchar2(100);
p_timeout number;
p_wsuser varchar2(100);
p_wspasswd varchar2(100);
p_ks_path varchar2(100);
p_ks_passwd varchar2(100);
begin
//SP which returns the values for the required parameters.
comppkg.getvcsinfo(
p_hostname,
p_port ,
p_serviceurl,
p_soapaction,
p_timeout,
p_wsuser,
p_wspasswd,
p_ks_path,
p_ks_passwd
Layer7_icengc_ws_tes(p_hostname,
p_port ,
p_serviceurl,
p_soapaction,
p_timeout,
p_wsuser,
p_wspasswd,
p_ks_path,
p_ks_passwd);
end;
This thing ends up with
29531. 00000 - "no method %s in class %s"
*Cause: An attempt was made to execute a non-existent method in a
Java class.
*Action: Adjust the call or create the specified method.
Im not understanding what wrong am i doing
pls help
Edited by: madhusudan on Feb 12, 2013 8:07 PMHello,
there is the forum {forum:id=65} for questions about using Java within Oracle.
Regards
Marcus
Edited by: Marwim on 13.02.2013 07:56
I could not find a suitable thread to post my PL/SQL question so iam posting it here.........You got the hint to the correct forum alread in another thread {message:id=10837976}
And if you think this is not related to Java but PL/SQL, then you should ask in {forum:id=75} -
Java Stored Procedures + oralce.xdb.XMLType + initxdbj.sql
In order to use XMLType object in java stored procedures, I need to import oralce.xdb.XMLType package. I got compiler error saying "Class oracle.xdb.XMLType not found" (See List1).
I check my installed package, sure enough these is no "oracle/xdb/XMLType" or any xdb related one. (See list2) This surprises me since my 9i/Solaris installation was successful and spotless one.
The 9i App Dev - XML doc states that script $ORACLE_HOME/rdbms/admin/initxdbj.sql could install that package. (See List3) The fact is no way this script could be found from Oracle901/Solaris8 or Oracle901/NT installations.
If java program moved to client and included xdb_g.jar in CLASSPATH, then it is fine as Doc declares. It just failed to compile in server as stored procedures.
Please help, Thanks.
Andy Ting DBA (301)240-2223, [email protected](now include Listings)
In order to use XMLType object in java stored procedures, I need to import oralce.xdb.XMLType package. I got compiler error saying "Class oracle.xdb.XMLType not found" (See List1).
I check my installed package, sure enough these is no "oracle/xdb/XMLType" or any xdb related one. (See list2) This surprises me since my 9i/Solaris installation was successful and spotless one.
The 9i App Dev - XML doc states that script $ORACLE_HOME/rdbms/admin/initxdbj.sql could install that package. (See List3) The fact is no way this script could be found from Oracle901/Solaris8 or Oracle901/NT installations.
If java program moved to client and included xdb_g.jar in CLASSPATH, then it is fine as Doc declares. It just failed to compile in server as stored procedures.
Please help, Thanks.
Andy Ting DBA (301)240-2223, [email protected]
====================================================================
List 1:
sql> select NAME,TYPE,SEQUENCE,LINE,substr(text,1,80) TEXT from user_errors order BY 1,2,3,4
NAME TYPE SEQUENCE LINE
TEXT
proto4a/database/XMLTypeTest JAVA CLASS 1 0
ORA-29535: source requires recompilation
proto4a/database/XMLTypeTest JAVA SOURCE 1 0
proto4a/database/XMLTypeTest:11: Class oracle.xdb.XMLType not found in import.
proto4a/database/XMLTypeTest JAVA SOURCE 2 0
proto4a/database/XMLTypeTest:12: Class XMLTYPE not found in import.
proto4a/database/XMLTypeTest JAVA SOURCE 3 0
Info: 2 errors
==============================================================
List 2:
sql> select OWNER,OBJECT_NAME,OBJECT_TYPE from all_objects
where upper(object_name) like '%XMLTYPE%';
OWNER OBJECT_NAME OBJECT_TYP
SYS /219cdace_AQxmlTypeInfoRespons JAVA CLASS
/a341e963_AQxmlTypeInfoRequest
XMLTYPE TYPE
XMLTYPE TYPE BODY
XMLTYPE_LIB LIBRARY
PUBLIC /219cdace_AQxmlTypeInfoRespons SYNONYM
/a341e963_AQxmlTypeInfoRequest
sql> select OWNER,OBJECT_NAME,OBJECT_TYPE from all_objects
where upper(object_name) like '%XDB%';
no rows selected
====================================================================
List 3:
Installing and using oracle.xdb.XMLType class
The oracle.xdb.XMLType is available in the xdb_g.jar file in the ORACLE_
HOME/rdbms/jlib where ORACLE_HOME refers to the Oracle home directory.
Using oracle.xdb.XMLType inside JServer:
This class is pre-loaded in to the JServer and is available in the SYS schema.
It is not loaded however, if you have upgraded your database from an earlier
version. If you need to upload the class into the JServer, you would need to run the
initxdbj.sql file located in the ORACLE_HOME/rdbms/admin directory, while
connected as SYS.
Using oracle.xdb.XMLType on the client:
If you need to use the oracle.xdb.XMLType class on the client side, then ensure that
the xdb_g.jar file is listed in your CLASSPATH environment variable.
===================================================================== -
Issue with Oracle.sql.NUMBER in Java Stored Procedure
When we try to make a call to the Oracle.sql.NUMBER(String) inside a java stored procedure and pass values from '01' to '09', it throws java.lang.StringIndexOutOfBoundsException: String index out of range: 3
We use Oracle 9.2.0.6 - JServer Release 9.2.0.6.0.
It works fine for other values. Please find below the code used for simulating the issue outside the application. Thanks.
create or replace and compile java source named testNumber as
import oracle.sql.NUMBER;
import java.sql.SQLException;
public class TestNumber
public static String convertNumber(String parm) {
NUMBER nTest;
try {
nTest = new NUMBER(parm);
return "TRUE";
}catch (SQLException sqle) {
return "FALSE";
create or replace function test_number (p_str in varchar2) return varchar2 as
language Java name 'TestNumber.convertNumber(java.lang.String) return
java.lang.String';
select test_number('05') from dual; - Throws exception ORA-29532: Java call terminated by uncaught Java exception: java.lang.StringIndexOutOfBoundsException: String index out of range: 3
select test_number('5') from dual; - Works fine
select test_number('010') from dual; - Works fineSiva,
I'm only guessing, but it could be an Oracle bug, in which case I suggest checking with Oracle Support.
(You do have a support contract, don't you? ;-)
Did you try compiling and running your java class "TestNumber" outside the database?
Class "oracle.sql.NUMBER" should be in Oracle's JDBC driver, I believe.
Good Luck,
Avi. -
SQL Server connection in Java Stored Procedures
Is it possible to establish a connection to microsoft sql server through java stored procedures. When I try to create a connetion to SQL Server I am getting the following exception in trace file
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java)
at java.sql.DriverManager.getConnection(DriverManager.java)
The connection details are correct and I am able to connect when I run the java code externally. Thanks in advance for the helpCan you connect to the MSSQL database from inside Oracle in (say) a SQL*Plus or SQL Developer session?
In other words, is the problem in the Java or the database linkages? Are you using Heterogeneous Services or Transparent Gateways?
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
Java Stored Procedure functions in SQL DML - multiple invocations
When running a java stored procedure as part of a DML statement the procedure is invoked 10-15 times for each row that is updated.
For example:
Update mytable set mycolumn = myjsp(somecolumn);
I undertand that this was a known bug with the JDBC driver. Has it been fixed? Is there a workaround?
We are using 8.1.6 on NT 4
Thanks
JulianHello ,
I tried here, and it seems to call the function once for each row
eg :
package package90;
public class Class1 extends Object {
public int get_data(int i)
return i+10;
Published the get_data function as
myproject67.get_data
SQL> connect scott/tiger@orcl8i
Connected.
SQL> set serveroutput on
SQL> exec dbms_java.set_output(5000);
PL/SQL procedure successfully completed.
SQL> select * from test_java;
NO1
10
10
SQL> insert into test_java values (20);
1 row created.
SQL> select * from test_java;
NO1
10
10
20
SQL> update test_java set no1=myproject67.get_data(no1);
Called
Called
Called
3 rows updated.
SQL> select * from test_java;
NO1
20
20
30
SQL> -
Connecting to SQL Server and MYSQL from a Java stored procedure
hope someone can help with this. i'm trying to connect to different databases (My SQL, SQL Server) from a java stored procedure. when invoking from within an oracle 9i database, i get the java exception error -
"Cannot connect to MySQL server on 135.177.196.75:3306. Is there a MySQL server running on the machine/port you are trying to connect to?java.security.AccessControlException)".
this store procedure works fine when invoked from outside of oracle. any replies would be greatly appreciated. thanks!the correct drivers have been loaded. it works when called from outside of oracle. only when invoking from within oracle do we get the error message "Cannot connect to MySQL server on 135.177.196.75:3306. Is there a MySQL server running on the machine/port you are trying to connect to?(java.security.AccessControlException)". it sounds like a permissions/security/configuration issue - oracle is not allowing access to the machine/port for the MySQL or SQL Server database. appreciate the responses so far.
-
Error while executing java stored procedure from a pl/sql procedure
We have a requirement where we need to execute JAVA code stored in an Oracle database (Java Stored Procedure). This code uses some JAR files which we have already loaded without any errors in the database.
The class file was also loaded in the database without any errors. But when we execute the method of this class (JAVA code), it gives the following error:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.NoClassDefFoundError
Is there any way of debugging the code and getting to know where exactly the problem is? Or, any tool/software available for doing the same.
Any pointers would be of great help!
Thanks in advanceHi Uday,
My guess is that there is a problem with your java stored procedure that is causing the "ExceptionInInitializer" error to be thrown. According to the javadoc:
is thrown to indicate that an exception occurred during
evaluation of a static initializer or
the initializer for a static variable
Since I didn't see any of your code in your post, I can't help you much more, I'm afraid. Perhaps if you would provide some more details, I may be able to help you some more. I think the following details would be helpful:
1. Complete error message and stack trace you are getting.
2. The section of your java code that you think is causing the problem.
3. Oracle database version you are using.
Good Luck,
Avi. -
Java Stored Procedure in EXECUTE IMMEDIATE
Hi,
I need advice for the following.
I'm on Oracle 11g R2. I'm testing application in Oracle 11gR1 and R2 and Oracle Express.
Purpose is to generate XML reports.
I have PLSQL Stored Procedure which does that, but since there is bug in Oracle11gR2 related to XMLTRANSFORM I have and Java Stored Procedure which is workaround. They are both compiled, valid etc.
Java class is :
import java.io.PrintWriter;
import java.io.Writer;
import oracle.xml.parser.v2.DOMParser;
import oracle.xml.parser.v2.XMLDocument;
import oracle.xml.parser.v2.XSLProcessor;
import oracle.xml.parser.v2.XSLStylesheet;
* This class is used as Java stored procedure
* There is a bug on Oracle11gR2, related to the limitation on the number of style sheet instructions
* This stored procedure is workaround when PLSQL code can not be used.
* File must not have package, otherwise is wrongly compiled in DB
public class JavaXslt {
public static void XMLTtransform(oracle.sql.CLOB xmlInput,oracle.sql.CLOB xslInput,oracle.sql.CLOB output) throws Exception{
DOMParser parser;
XMLDocument xml;
XMLDocument xsldoc;
try{
parser = new DOMParser();
parser.parse(xmlInput.getCharacterStream());
xml = parser.getDocument();
parser.parse(xslInput.getCharacterStream());
xsldoc = parser.getDocument();
XSLProcessor processor = new XSLProcessor();
XSLStylesheet xsl = processor.newXSLStylesheet(xsldoc);
Writer w = output.setCharacterStream(1L);
PrintWriter pw = new PrintWriter(w);
processor.processXSL(xsl, xml, pw);
}catch (Exception ex){
throw ex;
PROCEDURE Java_XmlTransform (xml CLOB, xslt CLOB, output CLOB) AS LANGUAGE JAVA
NAME 'JavaXslt.XMLTtransform(oracle.sql.CLOB, oracle.sql.CLOB, oracle.sql.CLOB)';
I'm calling Java stored procedure from PLSQL Stored procedure (if it is Oracle11gR2) like that :
Java_Proc.Java_XmlTransform(inputXML, xslt, res);
So till here everything works ok. XSLT as applied and output XML (res) is OK.
But when Oracle Express is used Java is out of the question, so there is no Java stored procedure. Howewer PLSQL Stored procedure is still needed.
So I had to put call to Java Stored procedure in EXECUTE IMMEDIATE statement in order to compile to PLSQL package.
But when I do that :
EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING inputXML, xslt, res;
result value CLOB (res) has zero length...
What am I missing? Should i set return value to Java class?
Hope my explanations are clear though.
ThanksHi odie_63,
Thanks for quick response.
I didn't clearly explained.
When using Oracle 11gR1 and Oracle Express I'm using only PLSQL Procedure.
When using Oracle 11gR2 i have to use Java Stored procedure because there is documented bug in R2.
That's why i have to use EXECUTE IMMEDIATE. I don't know which version is the client DB and whether there is or no Java procedures.
I did tried
EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, OUT res; and the result was ORA-06537: OUT bind variable bound to an IN position
When using IN OUT for last parameter i.e.
EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, IN OUT res;
there is no exception, but still DBMS_LOB.getlength(res) = 0
Thanks -
[b]Java Stored Procedure generating ora-932 in Oracle 9i [/b]
Hi ,
I have written a Java Stored procedure. And I have written a wrapper function as bellow
FUNCTION "GENERATE_AC_EXCEL_REPORT_FN"
( refCursorCall VARCHAR2, fromDate Date, ToDate Date,
nsn VARCHAR2, period varchar2, site VARCHAR2,
vendor VARCHAR2, spotbuyType VARCHAR2, dataType, VARCHAR2 )
return number
as LANGUAGE java
NAME 'accountingExcelReports.excelPrinter( java.lang.String, java.sql.Date, java.sql.Date, java.lang.String,java.lang.String , java.lang.String,
java.lang.String, java.lang.String , java.lang.String) return int';
This function returns 1000 upon successful execution.
This used to execute fine in Oracle 8.1.7.
We installed Oracle 9i recently.
Server version is 9.2.0.2.1.
Jserver version is 9.2.0.2.0 .
Now The function call works fine for the first time. And When execute it for sencond time in the same Session,
The program is erring out saying inconsistent data typpes.
This is happening during passing parameters.
SQL> select
2 generate_ac_EXCEL_report_fn('Period', to_date('7-1-2002','MM-DD-YYYY'),
3 to_date('7-31-2002','MM-DD-YYYY'), NULL,
4 NULL, NULL, NULL, 'ALL' ,'SPOTBUY') from dual;
GENERATE_AC_EXCEL_REPORT_FN('PERIOD',TO_DATE('7-1-2002','MM-DD-YYYY'),TO_DATE('7-31-2002','MM-DD-YYY
1000
SQL> select
2 generate_ac_EXCEL_report_fn('Period', to_date('7-1-2002','MM-DD-YYYY'),
3 to_date('7-31-2002','MM-DD-YYYY'), NULL,
4 NULL, NULL, NULL, 'ALL' ,'SPOTBUY') from dual;
select
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected IN Conversion failed
And upon further testing, i noticed this happens when the dates are passed. If date parameters are nulled out, Then the program executes perfectly any number of times.
The same program worked fine in Oracle 8.1.6
Any ideas?
Please help.
Thanks,
SrinivasHi Srinivas,
you shouldn't be calling conn.close() and its not needed when using Server Side Internal driver. If you are calling conn.close, then .....
extract from JDBC user guide
If you do call the close() method, be aware of the following:
All connection instances obtained through the defaultConnection() method, which actually all reference the same connection object, will be closed and
unavailable for further use, with state and resource cleanup as appropriate. Executing defaultConnection() afterward would result in a new connection
object.
Even though the connection object is closed, the implicit connection to the database will not be closed.
http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/advanc.htm#1001042
Elango.
Maybe you are looking for
-
How do I update my apple ID on iPad and iPhone after changing it?
Changed my email address which changed my Apple ID on this site but my iPhone and iPad are still showing my old ID. Can't seem to get it to update. Have tried turning it off and on. Won't let me change it. How can I get them to update to new apple ID
-
Update EKPV-KUNNR in shipping tab of ME21N/ME22N
Hello, I have a requirement where I have to update EKPV-KUNNR with a new value. I tried to use BADI ME_PROCESS_PO_CUST Method PROCESS_ITEM. I am using get_shipping_data to get the shipping details and then modifying EKPV-KUNNR and calling set_shippin
-
Why can't I import the u3d file as a view onto my pdf document?
After searching the web I finally found the instructions on how to import a 3d view onto a PDF document using Acrobat 7 Pro. I created the .u3d file and clicked on the TOOLS menu, then ADVANCE EDITING and then 3D Tool. I highlighted an area where I w
-
Inserting new line item into existing delivery using BAPI
Hi can you send me the code for inserting new line item into existing delivery either using BAPI or Function module. We are using SAP 4.7 version
-
Should cs5 be uninstalled after install of cs6
1. cs6 does not recognizes but will not run 3d party plugins that worked on cs5/64 2. should cs5 be uninstalled after upgrade to cs6