Parameter length limition passing to java stored procedure! help
hi:
i am working with java stored procedure to do some resource consuming work. i have to pass a long string (varch2) or bytes(log raw) which is larger than 32k which is the limitation
set by oracle.
is there a walk around?
another question:
i have to call java stored procedure from session beans ( weblogic app server) and how can i make sure the code
in session beans and that in java stored procedures to be in
the same transaction?
regards
daniel wang
Hi Daniel,
In answer to your first question: use a CLOB (for the long string)
and a BLOB (for the long raw). Do a search for CLOB and BLOB at the
Technet site:
http://technet.oracle.com
There are lots of resources including documentation and sample code.
In answer to your second question: first, let me say that the J2EE
forum is more suitable for that question (I haven't looked yet, but
you may have posted there as well!). Anyway, you need to set an
appropriate transaction attribute in your "ejb-jar.xml" descriptor
file for your session bean. If you want to make sure that the
session bean and java stored procedure participate in the same
transaction, I suggest using "Required", as in:
<trans-attribute>Required</trans-attribute>
Hope this helps.
Good Luck,
Avi.
Similar Messages
-
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? -
Problem passing REF CURSOR to JAVA STORED PROCEDURE
Hi,
I've written a small Java class with a static method and
imported that into Oracle 8i. The method expects a
java.sql.ResultSet object as parameter. According to the
documentation of Oracle, a REF CURSOR (cursor variable) maps to
java.sql.ResultSet in JDBC.
The definition of the Java Stored Procedure was accepted without
problems:
CREATE OR REPLACE PROCEDURE RESULTSETPASSINGTESTPROC (row
WASTypes.GenericCurType)
as language java
name 'sqlj.ResultSetPassingTest.testResultSetPassing
(java.sql.ResultSet)';
WASTypes is a package containing the definition of the generic
cursor:
CREATE OR REPLACE PACKAGE WASTYPES
is
TYPE GenericCurType IS REF CURSOR;
END WASTypes;
In a function I'm opening the cursor via
'Open cursorVariable for sqlStatement';
Then this cursor variable is passed to the java method and the
error ORA-03113 is shown.
I tried to solve the problem by changing the type of the
parameter to oracle.sql.REF without success.
Does anybody know what wents wrong?
Thanks in advance.
JanHi,
I've written a small Java class with a static method and
imported that into Oracle 8i. The method expects a
java.sql.ResultSet object as parameter. According to the
documentation of Oracle, a REF CURSOR (cursor variable) maps to
java.sql.ResultSet in JDBC.
The definition of the Java Stored Procedure was accepted without
problems:
CREATE OR REPLACE PROCEDURE RESULTSETPASSINGTESTPROC (row
WASTypes.GenericCurType)
as language java
name 'sqlj.ResultSetPassingTest.testResultSetPassing
(java.sql.ResultSet)';
WASTypes is a package containing the definition of the generic
cursor:
CREATE OR REPLACE PACKAGE WASTYPES
is
TYPE GenericCurType IS REF CURSOR;
END WASTypes;
In a function I'm opening the cursor via
'Open cursorVariable for sqlStatement';
Then this cursor variable is passed to the java method and the
error ORA-03113 is shown.
I tried to solve the problem by changing the type of the
parameter to oracle.sql.REF without success.
Does anybody know what wents wrong?
Thanks in advance.
Jan -
How to retrieve 'long' column with 32K length in Java stored procedure
For some reasons, we are not using CLOB, BLOB, or BFILE to store large objects and I have to live with LONG. So I wrote a Java stored procedure to insert, select and manipulate a LONG column by retrieving the LONG into a java.lang.String class (which happens to be the Java class mapped to the LONG SQL datatype). It all works fine as long as the length of the value being retrieved is less than the magic figure of 32767 bytes (which is the restriction on LONG and VARCHAR2 datatype in PL/SQL as well). So looks like Oracle's implementation of the JVM limits String values to a max of 32767 bytes. Suggestions on how to overcome this limitation (other classes that you suggest or do I have to move to files)?
Thanks,
Jeet
nullthe jvm has nothing to do with it ...
this is a pol/sql limitation on parameters in stored procedures.
and java stored procedures require a clal spec that makes the j-s-p look like a pl/qsl stored proc. -
Passing Tables back from Java Stored Procedures
Thomas Kyte has written (in reference to
trying to pass an array back from a stored
function call):
You can do one of two things (and both require the use of
objects). You cannot use PLSQL table types as JDBC cannot bind to
this type -- we must use OBJECT Types.
[snip]
Another way is to use a result set and "select * from
plsql_function". It could look like this:
ops$tkyte@8i> create or replace type myTableType as table of
varchar2 (64);
2 /
Type created.
ops$tkyte@8i>
ops$tkyte@8i>
ops$tkyte@8i> create or replace
2 function demo_proc2( p_rows_to_make_up in number )
3 return myTableType
4 as
5 l_data myTableType := myTableType();
6 begin
7 for i in 1 .. p_rows_to_make_up
8 loop
9 l_data.extend;
10 l_data(i) := 'Made up row ' | | i;
11 end loop;
12 return l_data;
13 end;
14 /
Function created.
ops$tkyte@8i>
ops$tkyte@8i> select *
2 from the ( select cast( demo_proc2(5) as mytableType )
3 from dual );
COLUMN_VALUE
Made up row 1
Made up row 2
Made up row 3
Made up row 4 [Image]
Made up row 5
So, your JDBC program would just run the query to get the data.
If the function "demo_proc2" cannot be called from SQL for
whatever reason (eg: it calls an impure function in another piece
of code or it itself tries to modify the database via an insert
or whatever), you'll just make a package like:
ops$tkyte@8i> create or replace package my_pkg
2 as
3
4 procedure Make_up_the_data( p_rows_to_make_up in
number ); 5 function Get_The_Data return myTableType;
6 end;
7 /
Package created.
ops$tkyte@8i>
ops$tkyte@8i> create or replace package body my_pkg
2 as
3
4 g_data myTableType;
5
6 procedure Make_up_the_data( p_rows_to_make_up in number )
7 as
8 begin
9 g_data := myTableType();
10 for i in 1 .. p_rows_to_make_up
11 loop
12 g_data.extend;
13 g_data(i) := 'Made up row ' | | i;
14 end loop;
15 end;
16
17
18 function get_the_data return myTableType
19 is
20 begin
21 return g_data;
22 end;
23
24 end;
25 /
Package body created.
ops$tkyte@8i>
ops$tkyte@8i> exec my_pkg.make_up_the_data( 3 );
PL/SQL procedure successfully completed.
ops$tkyte@8i>
ops$tkyte@8i> select *
2 from the ( select cast( my_pkg.get_the_data as mytableType
) 3 from dual );
COLUMN_VALUE
Made up row 1
Made up row 2
Made up row 3
And you'll call the procedure followed by a query to get the
data...
I have tried this, and it works perfectly.
My question, is what does the wrapper look
like if the stored function is written
in java instead of PL/SQL? My experiments
with putting the function in java have been
dismal failures. (I supposed I should also
ask how the java stored procedure might
look also, as I suppose that could be where
I have been having a problem)
nullThanks for the response Avi, but I think I need to clarify my question. The articles referenced in your link tended to describe using PL/SQL ref cursors in Java stored procedures and also the desire to pass ref cursors from Java to PL/SQL programs. Unfortunately, what I am looking to do is the opposite.
We currently have several Java stored procedures that are accessed via select statements that have become a performance bottleneck in our system. Originally the business requirements were such that only a small number of rows were ever selected and passed into the Java stored procedures. Well, business requirements have changed and now thousands and potentially tens of thousands of rows can be passed in. We benchmarked Java stored procedures vs. PL/SQL stored procedures being accessed via a select statement and PL/SQL had far better performance and scaleable. So, our thought is by decouple the persistence logic into PL/SQL and keeping the business logic in Java stored procedures we can increase performance without having to do a major rewrite of the existing code. This leads to the current problem.
What we currently do is select into a Java stored procedure which has many database access calls. What we would like to do is select against a PL/SQL stored procedure to aggregate the data and then pass that data via a ref cursor (or whatever structure is acceptable) to a Java stored procedure. This would save us a significant amount of work since the current Java stored procedures would simple need to be changed to not make database calls since the data would be handed to them.
Is there a way to send a ref cursor from PL/SQL as an input parameter to a Java stored procedure? My call would potentially look like this:
SELECT java_stored_proc(pl/sql_stored_proc(col_id))
FROM table_of_5000_rows;
Sorry for the lengthy post. -
Passing array from java stored procedure to plsql
I have a java store procedure that is parsing an xml document and returning element values to my plsql application(8.1.7). I'm mapping a java.lang.String return type to VARCHAR2. However I'm running into the 4k limit when trying to return a string from java that is over 4k. Truncation of varchar returning over 4k is a known issue in 8i.
So my next idea was to split that value of the element into 2000char and put in an array then pass that back to the plsql procedure. I know that oracle.sql.ARRAY can be converted into a plsql TABLE. But I believe you can only use the oracle.sql.ARRAY type when you are doing jdbc programming and are working with a connection.
SO FINALLY MY QUESTION IS...
Can anyone think of a solution that will allow me to pass over 4k of character data from my java stored procedure (not jdbc), back to my plsql app?
Thanks.My understanding is that oracle 8 has a 4k limitation on any plsql function return data. A varchar can hold 32k within a function/package, but it cannot return more than 4k outside it's scope.
Do you have an example you could share where you use the clob as a return type?
Thanks! -
Java Stored Procedure with LOB as input parameter (oracle 9i 9.2.0.6)
Hi,
Is there a way to pass CLOB as input and output as part of java stored proceudre in oracle 9i (9.2.0.6)?
I have to perform some data conversion on the CLOB data in java program and return the converted CLOB as output.
--Ramesh LokineniThe reason why I want to use java for conversion is because, I want to perform base64 encoding decoding on the content stored in CLOB column. I tried to use by chunking the data into smaller pieces and apply the base64 encoding, but when I decode the CLOB using base64, I am not getting the same data. Later when I read about how base64 encoding happens I realized chunking the data in CLOB doesn't work. That's when I started to diggin how I can pass CLOB to java stored procedures.
-
Java Stored Procedures, CLOB parameter
Hi all
I need to return s String parameter from a Java Stored Procedure but it is longer than 32000 chars, so I can4t use VARCHAR2 to publish it. I call that procedure from App. Server with JDBC.
I want to return a CLOB but I don4t know how to publish it, as I can4t do it from the deploy wizard.
Thank a lot!
Jose R.If you grant the right privileges to the user executing them..
(See the java developer guide for the details).
Note that calls to the OS through System.getRuntime().execxxx will run as the oracle user on the server side, that's why you have to be able to grant the right privileges before doing it. -
4gb file size limitation using java.io.* package in java stored procedure
Does anyone know about file size limitations when using java.io.* package inside java stored procedures. I have some java stored procedures that read and write to files. They error out when run as a java stored procedure within oracle on files over 4gb. I have no problems with these procedures when I test them outside of oracle.
I am using 10g Release 10.2.0.1.0, the java version returned by the Oracle JVM is 1.4.2_04
When I tested it outside of oracle I ran it using the java run time in ORACLE_HOME\jdk\bin and it works perfectly on files larger than 4gb.
Thank you for the UTL_FILE suggestion. I have considered using that but there is one method in Java that I can't seem to find a corresponding procedure for in PL/SQL.
RandomAccessFile.setLength()
This allows me to truncate a file. I have a need to strip bytes off the end of a file without creating a copy because I am working with large files and disk space may be limited. It is also much slower to read from the original file and writing the same bytes to a new file (minus the trailing bytes).
If anybody has any insight about the 4gb java.io limitation in Oracle JVM or has a workaround in PL/SQL for the RandomAccessFile.setLength() method in Java, I would really appreciate the help.
Thanks,
Thach -
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 -
SQLException: Cursor is closed while calling a java stored procedure
Hi,
I got the following error when trying to read from a cursor of a java stored procedure:
java.sql.SQLException: Cursor is closed
The java procedure is stored in the database and wrapped by a sql call. Then another java class executes the sql call.
The stored procedure looks like this:
import java.io.Reader; import java.security.MessageDigest; import java.sql.*; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import oracle.jdbc.OracleCallableStatement; import oracle.jdbc.OracleConnection; public class test { static Connection conn = null; static String username = null; static String password = null; static Integer userid = null; public static void main(String args[]) throws Exception { username = "keller"; password = "945435"; login(username, password); } public static String login(String in_username, String in_password) { String access = null; String password = null; try { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // Non OracleVM System.out.print("Verbindung wird initialisiert... "); conn = //DriverManager.getConnection("jdbc:default:connection:"); //conn.setAutoCommit(false); DriverManager.getConnection("jdbc:oracle:thin:@[...]:1521:[...]","[...]","[...]"); System.out.println("OK"); System.out.print("Logindaten werden ueberprueft... "); String sql = "SELECT matrikelnr, password FROM student WHERE name = ?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, in_username); ResultSet rset = pstmt.executeQuery(); while (rset.next()) { userid = rset.getInt(1); password = rset.getString(2); } access = "student"; pstmt = conn.prepareStatement(sql); if (password == null) { sql = "SELECT dozentnr, password FROM dozent WHERE name = ?"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, in_username); rset = pstmt.executeQuery(); while (rset.next()) { userid = rset.getInt(1); password = rset.getString(2); } pstmt = conn.prepareStatement(sql); if (password == null) { throw new SQLException("User nicht gefunden!"); } access = "dozent"; } //rset.close(); // Resultset schließen //pstmt.close(); // Statement schließen // MD5 Hash vergleichen MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(in_password.getBytes()); byte[] result = md5.digest(); StringBuffer hexString = new StringBuffer(); for (int i=0; i<result.length; i++) { if(result[i] <= 15 && result[i] >= 0){ hexString.append("0"); } hexString.append(Integer.toHexString(0xFF & result));
if (password != null) {
if (password.equals(hexString.toString())) {
System.out.println("OK");
} else {
throw new Exception("Falsches Passwort!");
catch(SQLException e) {
System.err.println("SQL Fehler!");
System.err.println(e.getMessage());
catch(Exception e) {
System.err.println("Fehler!");
System.err.println(e.getMessage());
return access;
public static void getLeistungsschein(int matrikelnr, ResultSet[] rout)
ResultSet rs = null;
try
System.out.print("Berechtigung ueberpruefen... ");
if (userid != matrikelnr)
throw new Exception("Zugriff verweigert, keine Berechtigung!");
int mnr = matrikelnr;
((OracleConnection)conn).setCreateStatementAsRefCursor(true);
PreparedStatement ps = conn.prepareStatement("select bezeichnung, note from klausur inner join leistungsschein on klausur.KLAUSURNR=leistungsschein.KLAUSURNR where matrikelnr= ?");
ps.setInt(1, mnr);
rs = (ResultSet)ps.executeQuery();
rout[0]= rs;
catch(SQLException e) {
System.err.println("Fehler!");
System.err.println(e.getMessage());
catch(Exception e) {
System.err.println("Fehler!");
System.err.println(e.getMessage());
The sql call:
create or replace
procedure pgetleistungsschein(matrikelnr in number, cur OUT refcurpkg.refcur_t) is
language java name 'Klausurverwaltung.getLeistungsschein(int, java.sql.ResultSet[])';
And finally the wrapper is called by another java programm, see this:
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleResultSet;
import oracle.jdbc.OracleTypes;
public class cursortest {
public static void main(String[] args) {
try{
//-- Oracle Treiber laden
Class.forName( "oracle.jdbc.driver.OracleDriver" );
Connection c = DriverManager.getConnection( "jdbc:oracle:thin:@sligo.fh-trier.de:1521:ubuntu", "dbsem_java","javajava");
CallableStatement stmt = null;
ResultSet rs1 = null;
int matrnr = 945098;
// Call PLSQL Stored Procedure
stmt = (CallableStatement)c.prepareCall("{ call ? := getklausuren(?) }");
stmt.setInt(2, matrnr);
// 2nd parameter is OUT paremeter
stmt.registerOutParameter(1, OracleTypes.CURSOR);
// Execute the callable statement
stmt.execute();
//Cursor in ResultSet einlesen
rs1 = ((OracleCallableStatement)stmt).getCursor(1);
ResultSetMetaData rsmd = rs1.getMetaData();
int anzSpalten = rsmd.getColumnCount();
List<String[]> zeilen = new ArrayList<String[]>();
while(rs1.next())
String[] zeile = new String[anzSpalten];
for (int i=1; i<=anzSpalten; i++)
zeile[i-1]=rs1.getString(i);
zeilen.add(zeile);
String[][] array_angeb_klaus = (String[][])zeilen.toArray(new String[zeilen.size()][anzSpalten]);
//**** ENDE
rs1.close();
stmt.close();
//c.close();
catch (SQLException e){
System.out.println(e);
catch (ClassNotFoundException f){
System.out.println(f);On top of what jschell says, this just looks wrong in terms of how Oracle's internal Java works as well.
[Have a look here |http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/refcur/index.html] (unless things have changed significantly over the past few years for Oracle Java).
Is the db you are querying a different one to the one this Java is stored in? -
21700 while calling java stored procedure in 9i
I create a java stored procedure that takes a varray of a rowtype. When I call that procedure, I get an ora-21700. If I remove the varray from the parameter list, I can call the procedure okay. My goal is to create a generic java procedure that can take a rowtype from any table and create XML. Once I get the oracle.sql.ARRAY into my code, I am okay. I just can't seem to pass it in. I have pasted my code below:
Java:
import oracle.sql.*;
public class test {
public static String sayHello() {
return("Hello, World!");
public static void genXML(oracle.sql.ARRAY a, oracle.sql.CLOB c) throws Exce
ption {
c.putString(1,"<test>This is a test!</test>");
PL/SQL:
create or replace package mike is
type dummy_record is varray (1) of dummy%rowtype;
PROCEDURE GENERATE_XML(i dummy_record, c CLOB);
FUNCTION SAYHELLO RETURN varchar2;
end mike;
show errors
create or replace package body mike is
PROCEDURE GENERATE_XML(i dummy_record,c CLOB)
AS LANGUAGE JAVA
NAME 'test.genXML(oracle.sql.ARRAY,oracle.sql.CLOB)';
FUNCTION SAYHELLO RETURN varchar2
AS LANGUAGE JAVA
NAME 'test.sayHello() return java.lang.String';
end mike;
show errors
DDL:
SQL> describe dummy
Name Null? Type
USERNAME VARCHAR2(20)
ID NUMBER
Test Script:
declare
m Mike.dummy_record := Mike.DUMMY_RECORD();
c CLOB;
begin
m.extend;
select xml into c from t_clob;
for rec in (select * from dummy)
LOOP
m(1) :=rec;
mike.generate_xml(m,c);
end loop;
end;
And finally, the output:
declare
ERROR at line 1:
ORA-21700: object does not exist or is marked for delete
ORA-06512: at "MMANGINO.MIKE", line 0
ORA-06512: at line 10
Sorry this post is so long, but I wanted it to be complete!
MikeThe first solution is to not do that in java in the first place.
DDL should be in script files which are applied to oracle outside of java.
Other than I believe there are some existing stored procedures in Oracle that take DDL strings and process them. Your user has to have permission of course. You can track them down via the documentation. -
Java stored procedure problem(oracle db)
HI,
we have a java stored procedure with the following definition, and that works as we want it to:
CREATE OR REPLACE FUNCTION processBulletin(in_varchar VARCHAR2) RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'JavaParser.Bufr_Ingest.processBulletin(java.lang.String) return java.lang.String';
And the Java portion:
public static String processBulletin(String in_bull)
... do something with in_bull
The problem is that we've recently discovered that the 32767 size restiriction on the input parameter varchar2 is too small. I don't want to rewrite the entire Java procedure. I figured the simplest (or at least temporary)solution would be to have the Java procedure accept a CLOB, convert that clob to a string and continue as it would. I was hoping someone might be able to tell me if the following would be possible:
CREATE OR REPLACE FUNCTION processBulletin(in_clob CLOB) RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'JavaParser.Bufr_Ingest.processBulletin(oracle.sql.CLOB) return java.lang.String';
And the Java portion:
public static String processBulletin(oracle.sql.CLOB in_clob)
String in_bull = clob_in.getSubString(1, (int)clob_in.length());
... do something with in_bull
ThanksI don't know about Java stored procedures, but in JDBC you usually use streams to work with CLOBS. Here's Oracle JDBC Developers Guide, Working with LOBs
-
Legal Java Stored Procedure method parameters
Hi,
I'm trying to establish whether Java arrays can be returned from Java Stored Procedures. It seems that I can only return single length (i.e. 1) arrays which is highly restrictive.
If I am creating a Java Stored Proc that will be called from pure Stored Proc land, and my JavaSP could raise a number of exceptions I'm avoiding this and instead trying to return an "error status" as a parameter that the caller can query. i.e. I want the "error status" to be an array of (3) strings including a severity, an error number, and a string containing the Java exception.
Is there a way to do this without requiring all my methods to have 3 String[] parameters, one for each part of the error status? Or is there a better way?
regards
--malcolmHi,
You could consider using object types to store your exception information. In that case you will have to use JPublisher to map the sql types to java types. JPublisher enables you to specify and customize the mapping of SQL object types, object reference types, and collection types (VARRAYs or nested tables) to Java classes.
For more info on JPublisher refer : http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96658/toc.htm
For some Java Stored Procedure samples using object types refer to http://otn.oracle.com/sample_code/tech/java/jsp/oracle9ijsp.html -
How to write call specs for a java stored procedure that takes a nested obj
Example Class :
public class B {
int number;
String str;
public class A {
private B[] _childern;
public B[] getChildern(){
return _children
public static void saveAll(A a) throws SQLException {
B[] children = a.getChildern();
for(int i=0; i<children.length; i++){
saveChild(children);
public static void saveChild(B ch)throws SQLException {
// do something
What would be the call specification for the method A.saveAll(A)? Your help will be apprecited.
Thank you
AjmalIn other words, How to pass a Java Object from a Java stored procedure to a Java client ???
Hello,
I don't know to deal with a Vector object that has been generated from a stored procedure.
Should I create first in the JDBC client and pass it as argument to the procedure ?
Thanks in advance. Here is an extract ...
On the client side :
<<
Vector buffer = new Vector();
CallableStatement call =
con.prepareCall ("{call my_procedure_run (?, ?)}");
call.registerOutParameter(2, java.sql.Types.JAVA_OBJECT );
call.setString (1, "bla bla bla");
call.setObject (2, buffer);
call.execute ();
buffer = (Vector)call.getObject (2);
>On the Java stored procedure
<<
public class my_procedure
public static void Run(String input_value, Vector buffer)
// ??? Vector buffer = new Vector();
try
while ( true )
buffer.addElement(...) ;
catch(Exception ex) { }
Maybe you are looking for
-
My iPhone 5 no longer charges, and I got it in November 2012.
Any advice on what I should do?
-
Compatability between Windows 8 and my HP Officejet J3680
I just got a new laptop with Windows 8. That is hard enough to get used to. Now my printer does not communicate with my laptop. I have downloaded drivers and updates. Changed portsand used HP Doctor whatever. Nothing seems to work. Help. This q
-
I have an external drive I use as my Time Machine backup location. Recently, I started getting an error on it. It tells me there is a problem, and to repair it with Disk Utility. Disk Utility cannot verify the disk, and needs me to repair it, but i
-
Where to upload images on-line for storyboarding?
Where to upload images on-line for storyboarding? Or what does it take to produce a storyboard from a Adobe Story Plus Script? Any suggestions are welcome ; )
-
No one knows how to fix! Help me!
I'm posting this after a couple of days running around on the net and several calls to the "apple call center" with no answers. Here is the problem: My 2gig iPod Nano's screen never changes off of the language screen. This is what I've done: Pressed