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.
Jan

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.
Jan

Similar Messages

  • Passing Ref Cursor to Oracle Stored Procedure Via C#

    Hi all,
    I am new to oracle and stuck with an issue. I have three insert stored procedures for three different tables. Two of them have multiple rows to be inserted, which is currently done via iterating through each row and insert to db in C# code. My requirement is to merge these three procedures in one and instead of iterating from C# code send table rows as (ref cursor or collection) to procedure and the procedure will handle the rest.
    I read that ref cursor only works if you're data is in database as it reference the memory but in my case data is build on client side.
    I am using Oracle 11i and ASP.Net 2.0
    Can any help me on this please?
    Edited by: 929463 on Apr 23, 2012 12:38 AM

    929463 wrote:
    I am new to oracle and stuck with an issue. I have three insert stored procedures for three different tables. Two of them have multiple rows to be inserted, which is currently done via iterating through each row and insert to db in C# code. My requirement is to merge these three procedures in one and instead of iterating from C# code send table rows as (ref cursor or collection) to procedure and the procedure will handle the rest.Why a single procedure? How is the procedure to determine the target table to insert the data into? And please - no dynamic SQL as that is 99% of the time wrong.
    A ref cursor is something that PL/SQL creates - with the purpose of passing the cursor handle to your code. This enables the actual SQL statement for that cursor to be moved from client code, into a PL/SQL stored proc. It abstracts the client from having to understand SQL, understand the data model and so on. All clients use the same PL/SQL proc and thus the same code for creating that cursor. Thus no issue of some clients getting it half right or half wrong and dealing with data inconsistencies between clients.
    The PL/SQL proc can be tuned and optimised, modified for catering for data model changes and so on. Without your client code having to be even recompiled as it is isolated against these server changes.
    For all other interaction (running PL/SQL code, doing insert/update/delete/etc SQL statements), you need to create the cursor yourself in your code.
    Also, the SQL engine only sees cursors. There are no differences between cursors. The client (e.g. PL/SQL) can call it a reference cursor, or an implicit cursor, or a DBMS_SQL cursor.. the SQL engine does not know that and does not care.
    A ref cursor is simply a special type of client interface to a SQL cursor, allowing PL/SQL to create that SQL cursor and then pass the handle of that SQL cursor to other code to consume that cursor.
    Okay, so if you want to insert data, you need in your code to create a cursor. This can be a SQL INSERT cursor - the actual insert statement. Or it can be a PL/SQL call - an anonymous PL/SQL code block that calls a stored proc that performs the insert (after applying validation and business logic).
    The cursor will have one or more bind variables. Your client will pass values for these variables and the server-side code (SQL or PL/SQL) will be executed using this as variable data.
    You can for example create a cursor as follows:
    begin
      DoFunkyInsert( :1, :2, :3 );
    end;
    {code}
    3 bind variables are expected. You can now in the client build an array for each of these variables, containing a 100 values each (total of a 100 rows to insert). Do a single execute of the cursor, and tell Oracle that the bind is actually a 100 element array.
    The complete array ships to Oracle - Oracle opens a loop and execute the cursor for each element in the array.
    This is called bulk binding.
    An alternative approach is to define the bind variable as a collection (a non-scalar value). And then code the PL/SQL procedure to open a loop and iterate through the collection/array, inserting a row per iteration.
    The binding itself is more complex as your code know needs to understand Oracle object types and be able to define an array/collection that is a valid Oracle non-scalar data type.
    The +Oracle Call Interface+ (OCI) is quite flexible in this regard. However, as you work via an abstraction layer (e.g. ADO, OleDB, ODBC, etc) your code is subject to whatever functionality this abstraction layer makes available to your code. And this is seldom includes all the power, functionality and flexibility of the (more complex) OCI itself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • 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)
    null

    Thanks 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.

  • How to get an UPDATABLE REF CURSOR from the STORED PROCEDURE

    using C# with
    ORACLE OLE DB version: 9.0.0.1
    ADO version: 2.7
    I returns a REF CURSOR from a stored procedure seems like:
    type TCursor is ref cursor;
    procedure test_out_cursor(p_Dummy in varchar, p_Cur out TCursor) is
    begin
         open p_Cur for select * from DUAL;
    end;
    I create an ADO Command object and set
    cmd.Properties["IRowsetChange"].Value = true;
    cmd.Properties["Updatability"].Value = 7;
    cmd.Properties["PLSQLRSet"].Value = 1;
    cmd.CommandText = "{CALL OXSYS.TEST.TEST_OUT_CURSOR(?)}";
    and I use a Recordset object to open it:
    rs.Open(cmd, Missing.Value,
    ADODB.CursorTypeEnum.adOpenStatic,
    ADODB.LockTypeEnum.adLockBatchOptimistic,
    (int) ADODB.CommandTypeEnum.adCmdText +
    (int) ADODB.ExecuteOptionEnum.adOptionUnspecified);
    The rs can be opened but can NOT be updated!
    I saved the recordset into a XML file and there's no
    rs:baseschema/rs:basetable/rs:basecolumn
    attributes for "s:AttributeType" element.
    Any one have idea about this?
    thanks very much

    It is not possible through ADO/OLEDB.
    Try ODP.NET currently in Beta, it is possible to update DataSet created with refcursors. You need to specify your custom SQL or SP to send update/insert/delete.
    As I remember there is a sample with ODP.NET Beta 1 just doing this.

  • REF CURSOR from Java Stored Proc

    Does Oracle 8i/9i allow to return REF CURSROR from Java Stored Procedure?

    Sorry,
    No I don't think this type of Java->SQL mapping was ever fixed. I know it was discussed here on the OTN forums as far back as the 8i driver, but I don't think they have ever implemented this. Perhaps someone who has actually made it work will speak up.

  • Ref Cursors in a stored Procedure

    Can some help me with an answer to the below question.
    How many ref cursors can be declared in a stored procedure in oracle?
    Thanks

    user533016 wrote:
    You are right. Keeping so many cursors open is not good at all. But i was doing this to see where it breaks and is there something that definitely controls the number of refcursors in allowed a PL/SQL block.As Karthick already mentioned you have the OPEN_CURSORS parameter which defines how many open cursors you may have in any one session.
    However, this doesn't just apply to Ref Cursors. If you open explicitly defined cursors then this will also count towards that, as well as issuing select statements as they are implicit cursors... e.g.
    declare
      cursor c1 is
        select * from emp;
      cursor c2 is
        select * from dept;
      v_c1 c1%ROWTYPE;
      v_c2 c2%ROWTYPE;
      v_cnt number;
    begin
      open c1; -- now we have 1 open cursors
      loop
        fetch c1 into v_c1;
        exit when c1%notfound;
        open c2;  -- now we have 2 open cursors
        loop
          fetch c2 into v_c2;
          exit when c2%notfound;
          select count(*)  -- this counts as opening cursor number 3.
          into v_cnt
          from payroll;
          -- after the select statement the implicit cursor is automatically closed, so now we have 2 open again
        end loop;
        close c2; -- after this we just have 1 more open
      end loop;
      close c1; -- after this we have no open cursors
    end;

  • REF CURSOR RETURNED FROM STORED PROCEDURE OPENED WITH CURRENT_USER PRIVILEGES

    Hi.
    I was wondering if anyone knows when this bug will be fixed. The bug# is 899567 off of metalink.
    I am running into this problem as well, and we do not want to use OCI/SQLNet as the fix. We have an application with secure data concerns and only want to give access to stored procedures to an application user.
    Thanks,
    Brad

    I'm using version 8.1.6.0.0 on a W2K server.
    PS: a strange behaveour
    if i try to insert a row using the following anonymous pl/sql block
    begin
    insert into objects select 2, 'B', ref(c) from meta.classes c where id =1;
    end;
    i get the following error msg
    ERROR at line 1:
    ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-302: component 'OBJ_T' must be declared
    but if i use only the sql command from the sql plus prompt
    insert into objects select 2, 'B', ref(c) from meta.classes c where id =1;
    the row is inserted.
    OBJ_T is the object type(id number, label varchar2, class ref class_t),
    OBJECTS is a table of obj_t,
    CLASS_T is an object type(id number, label varchar2)
    CLASSES is a table of CLASS_T.
    null

  • 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)
    null

    Iam 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?

  • 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?

  • Problem of java stored procedure

    hi,
    now I use the oracle9i JDeveloper9.0.3.1 to develop java stored procedure and then publish it to oracle9i database.
    In the database I create PL/SQL procedure to invoke the java stored procedure.But I encounter the problem,that is ,when I run the PL/SQL procedure ,it throw the java.lang.NullPointerException ,while the java class,the java stored procedure can run correctly invoked by the main class of java.The code of the java stored procedure is as follows:
    import java.sql.*;
    import java.util.Properties;
    public class SQLServerEventDistribute
    public static void sqlServerSaveData(String hostName,String databaseName,String user,String password,String tableName,int x1,int y1,int x2,int y2,String ip)
    String url="",sql="",userName="",passwd="";
    Connection connection;
    Statement statement;
    url="jdbc:microsoft:sqlserver://"+hostName+":1433;DatabaseName="+databaseName+";User="+user+";Password="+password;
    sql="INSERT INTO "+tableName+" VALUES("+x1+","+y1+","+x2+","+y2+",'"+ip+"')";
    Properties property=new Properties();
    property.setProperty(userName,user);
    property.setProperty(passwd,password);
    try
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    // DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
    connection=DriverManager.getConnection(url,property);
    statement=connection.createStatement();
    statement.execute(sql);
    }catch(ClassNotFoundException connectSQLServerEx)
    System.out.println(connectSQLServerEx.getMessage());
    catch(SQLException connectSQLServerEx)
    System.out.println(connectSQLServerEx.getMessage()+connectSQLServerEx.getErrorCode());
    the main class is as follows:
    public class Test
    public static void main(String[] args)
    SQLServerEventDistribute.sqlServerSaveData("gsm","gsmd","sa","sa","IPBinding",11,45,24,21,"23.1.248.12");
    and the PL/SQL procedure is as follows:
    PROCEDURE TEST AS
    BEGIN
    SQLSERVERSAVEDATA('gsm','gsmd','sa','sa','IPBinding',11,45,24,21,'23.1.248.22');
    END;
    How can I deal with it?
    can you tell me?
    thanks

    Hi JavaQQ,
    This is just a guess, but I think you need to load the
    Micro$oft SQLServer JDBC driver into the Oracle
    database (using the "loadjava" utility).
    In any case, there are several ways -- apart from JDBC
    -- for accessing a different database from within an
    Oracle database. Have you tried searching the Oracle
    Web sites for suitable products?
    Hope this helps.
    Good Luck,
    Avi.abramia ,thank you very much.
    but I have load the Microsoft SQLServer JDBC driver into the Oracle database .
    When I debugged the PL/SQL procedure,the exception was thrown at line connection=DriverManager.getConnection(url,property);
    What's the problem with it?

  • Java Stored Procedure Deployment Problem with JDev 3.1.1.2

    Dear JDeveloper Team:
    I am having a problem deploying a test Java stored procedure to the database. In the Deployment Profile Wizard Connection tab, it displays no connection in the connection dropdown even though I have defined some connections that have been sucessfully connected to the database.
    Please help.
    Thanks,
    Tom

    Tom,
    Verify that your Connections are valid as follows:
    Double Click on the Connections folder of JDeveloper Navigator.
    This opens up the Connection Manager.
    Make sure you have defined JDBC Connections.
    Pick your connection of intrest and select Edit... and then press the Test button to test the conneciton.
    If this is a valid JDBC connection, then it should appear later when you run the deployment wizard.
    -John

  • DBMS_JOB on Java Stored Procedure problem

    Hi all,
    (running on Oracle 9i : 9.2.0.7.0 64bit on HP/UX)
    I have a Java Stored procedure that reads a table
    One of the fields in this table is a CLOB containing some more SQL.
    We then executeQuery() that SQL (and e-mail the output).
    (Obviously I also have PL/SQL wrapper around it, which we'll call PROCNAME).
    For certain pieces of SQL, this second executeQuery() fails throwing ORA-00942, but only when run from a DBMS_JOB(!).
    Calling "CALL PROCNAME('argument')" from sqlplus/toad works fine, but setting "PROCNAME('argument')" to run as a DBMS Job fails on some SQL with the above error. (All as the same username).
    java.lang.StackTraceElement doesn't seem to exist in Oracle java, so the only error I have to go on is e.getMessage() from SQLExecption which returns:
    ORA-00942: table or view does not exist
    Any help at this strangeness would be appreciated!
    nic

    Hi Cris:
    May be is a problem of the effective user which is running the procedure.
    Which is the auth_id directive at the PLSQL call spec?
    Look at this example procedure UploadNews for example:
    http://dbprism.cvs.sourceforge.net/dbprism/cms-2.1/db/cmsPlSqlCode.sql?revision=1.21&view=markup
    this procedure calls to the cmsNews.doImport which is implemented as Java Stored Procedure.
    Also check if your loadjava operation is not using -definer flag.
    Best regards, Marcelo.

  • Re   Java Stored Procedure Problem

    Ben
    There appear to be some problem with the forum. It doesn't want to show my response to your post with the subject "Java Stored Procedure Problem". See the answer to this thread for an example of how to do this...
    Is there a SAX parser with PL/SQL??

    Ben
    There appear to be some problem with the forum. It doesn't want to show my response to your post with the subject "Java Stored Procedure Problem". See the answer to this thread for an example of how to do this...
    Is there a SAX parser with PL/SQL??

  • 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
    Thanks

    I 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

  • Problem in running a java stored procedure&optimum settings for this needed

    hi
    we are using java stored procedures to read huge data from database tables and transfer them to another system.
    the procedure is running fine but it fails after transferring 60000 records, the execution of procedure here does not terminate but keeps running with out performing any data transfer....since it does not give any error it is difficult for us to know what the actual problem is !!!!!!
    i have checked the code many a time and i dont see any infinite loops in that code.
    please give any pointers on why this might be happening?
    please also give all the parameters which need to be taken care of while running a java stored procedure
    thanks
    regards
    asif

    But the same thing works fine with a jdbc program
    the table name is converted
    The same convert.transform method is being used to do the conversion
    please help
    ISQL is similar to SQL prompt inOracle
    it is like,
    ISQL>
    Regards
    khurram

Maybe you are looking for

  • Java seems to be having a buffer error....

    Ok let me start by saying I do not know any JAVA programming. I just trying to fix something that some dump programmer charged me a ton of money for and it does not work right... The program reads a XML stream and creates XML files... The read works

  • IPhoto Book photos going negative

    Making a book in IPhoto. Past ones were super. But now an issue. I am dropping in black and white images into the pages. These are scanned files from Nikon Coolscan and converted to jpgs. When they drop, they appear as a negative, reversed from the f

  • MFP M177FW non standard paper sizes

    hi all i'm using libreoffice on both windows and linux (mint ubuntu and debian testing) and sometimes i have to print on very non standard sizes: 102 * 333 mm it's a huge pain to decently print on such a paper: is there an easy workaround, especially

  • Need help with log in (says i have no device registered - but I do!)

    I've somehow lost my iphone 5 - and really need to use find my iphone in icloud...but when I try to log in, I can't get past this message.  The thing is, I've used this feature before...and my phone was definitely set up.  Does anyone have any sugges

  • Table QMEL is partially active ERROR AS Adjustment terminated in step 6

    Dear all, i  have added some fields in qmel by using append structure but i am then i am trying to activate table via tcode se14 but i am error  message as  Adjustment terminated in step 6. Can any one help me on this... Thanks Sivakumar Ramakrishnan