Using MapViewer from PL/SQL vs Java

Hi group!
The MapViewer User's Guide has this to say about using MapViewer from PL/SQL:
"The usage model for the SDO_MVCLIENT package is almost identical to that of
MapViewer JavaBean-based API" etc etc .. "For usage and reference information about specific functions or procedures, see the description of the associated JavaBean-Based API. methods and interfaces in Chapter 4"
If I don't misunderstand the basic concept, in a Java Web App (using the MapViewer Bean) you create a MapViewer object for each HTTP-user-session, like so:
MapViewer mv = new MapViewer("http://my_corp.com:8888/mapviewer/omserver");
... which you would then store in the user's session object, so that the MapViewer Bean conveniently holds the map's state on the user's behalf.
To do the equivalent in PL/SQL, the User's Guide suggests:
"connect scott/tiger
call sdo_mvclient.createmapviewerclient(
'http://www.mycorp.com:8888/mapviewer/omserver') ;
The preceding example creates, in the current session, a unique MapViewer client
handle to the MapViewer service URL"
Does "current session" refer to the HTTP-user-session? While I've used PL/SQL before, I've not used the PL/SQL Web Toolkit. Is the session handling implicit here (and invisible?) or should the sdo_mvclient be subsequently stored in the PL/SQL equivalent of a (J2EE) HttpSession object?
YT

Part of the answer will depend on how you plan to deploy the application. If you have a few, local clients you could go with the traditional client/server model. If you have a lot of clients and/or they are spread out over a relatively large area (like a campus setting), a web front-end will save you a lot of hassels down the road when it comes time to upgrade.
Regardless of the the front end, I can tell you that I have been greatly impressed with the throughput you can get by moving most of the code to PL/SQL packages. A few years ago we reworked a VB/Oracle app by moving a lot of the code out of VB and into packages, leaving the client to essentially call procedures and format the output. We had more than a 3x performance increase on the same hardware and our network utilization decreased noticably.
I am now in the process of replacing the client code with Java servlets/JSP, primarily because of the maintenance hassles I mentioned earlier. There are some limitations with an HTML page but most of these have been cosmetic so far.
We are still relying heavily on PL/SQL packages. The servlet code basically gets a request, calls a package to get the data, then hands the results to a JSP page. The JSP then formats the output and sends it to the client. We are little more than halfway through the re-write, but it appears performance will increase again. Not as noticably as before, but I will take what I can get. As you have seen, once something is rolled out it always ends up getting used more than you anticipated. Better to over-engineer now than have to patch it once it is live.
HTH

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.

  • From PL/SQL call java class present in Application server

    Hi,
    I need to call a java class file which is present on the application server. the call has to be made from pl/sql.
    I do not want to make use of the java stored procedures for this.
    Is there a way to call a class file residing on the application server from a pl/sql.
    Please help me out.
    Thanks & Regards
    Kamlesh

    New idea. DDL isn`t working but if i would make some DQL ? Like select??
    I`m trying to deploy java class like this:
    public class test {
         public static String say()
              throws SQLException{
                   Connection conn = new OracleDriver().defaultConnection();
                   String sql = "Select names from pdb_proteins where numbers=61";
                   try {
                        // Load the Oracle JDBC driver
                        Class.forName("oracle.jdbc.OracleDriver") ;
                        System.out.println("Oracle JDBC driver loaded ok.");
                        } catch (Exception e) {
                        System.err.println("Exception: "+e.getMessage());
                   try {
                        ResultSet rset = null;
                        PreparedStatement pstmt = conn.prepareStatement(sql);
                        rset=pstmt.executeQuery(sql);
                        String wynik = null;
                        wynik = rset.getString(1);
                        return wynik;
              } catch (SQLException e) {
                   System.out.println("Connection Failed! Check output console");
                   e.printStackTrace();
                   return "nope";
    Then invoke with PL/SQL function
    and i`m getting error ORA-29534: object SYSTEM.oracle/jdbc/OracleDriver
    Could someone help me with this? How i could register jdbc driver inside Oracle db??
    Edited by: Rado_mir on 2013-06-03 02:42

  • How use DLL from PL/SQL

    Dear Mr/Mrs,
    My system is
    1.Oracle Database 10g express edition(with apex 3.2)
    2.Windows 2003 server
    3.GSM Modem(usb cable + Vendor Provided dll for developer)
    4.Mobile SIM card
    Now ,i want to send SMS from Database.
    N.B: email to sms is not my intention
    Thanks
    Engr.M.K Chowdhury

    Hi,
    What's wrong with the last answer Re: Using DLL from apex ?
    Regards
    Peter

  • Error while invoking webservice using UTL_HTTP from PL/SQL Block

    Hi All,
    I am invoking a webservice (SOAP Request) from a PL/SQL block using UTL_HTTP package.
    I am able to send the complete request and am getting the required instance on the BPEL Console, but the process is erroring out while getting response back.
    and the PL/SQL Block is ending in error mentioned below:
    ERROR at line 1:
    ORA-29266: end-of-body reached
    ORA-06512: at "SYS.UTL_HTTP", line 1321
    ORA-06512: at "APPS.CSM_BPEL_TEST_PKG", line 34
    ORA-06512: at line 1
    Package is completing successfully if i test in local DB and local BPEL.
    But giving above error in client's.
    Can anyone let me know what is the cause of this.
    Thanks in advance

    I got it working by making process Synchronous.
    But with asynchronous process it is still same error.
    Thanks...

  • Using Oracle from MS SQL 2005

    I am having a strange problem while running an SQL statement in MS SQL 2005 that uses a linked Oracle server. I am getting the following error:
    OLE DB provider "OraOLEDB.Oracle" for linked server "OG" returned message "ORA-01403: no data found".
    Msg 7346, Level 16, State 2, Line 1
    Cannot get the data of the row from the OLE DB provider "OraOLEDB.Oracle" for linked server "OG"
    I am getting the error on the following SQL statement (OG is the Oracle server):
    SELECT Inv.AreaNo, Inv.CatType, Inv.CatNo, Inv.ItemNo, Inv.NumAvail, Inv.NumTotal, Inv.Active,
    IH.AID, IH.NumOut, IH.DateOut, IH.WorkerOut, IH.NumIn, IH.DateIn, IH.WorkerIn,
    CC.CatID, CC.CatName, CC.BinItem, CC.Active, OG.LASTNAME, OG.FIRSTNAME, OG.MIDDLENAME
    FROM ItemInventory AS Inv
    LEFT JOIN CatCodes AS CC ON Inv.AreaNo = CC.AreaNo AND Inv.CatType = CC.CatType AND Inv.CatNo = CC.CatNo
    LEFT JOIN ItemHistory AS IH ON Inv.AreaNo = IH.AreaNo AND Inv.CatType = IH.CatType AND Inv.CatNo = IH.CatNo AND
    Inv.ItemNo = IH.ItemNo
    LEFT JOIN OGL..D.LE AS OG ON AID = OG.PK
    WHERE Inv.AreaNo = 0 AND Inv.CatType = 0
    What's strange is that the following SQL statement works fine. The only difference between table ItemHistory (above) and ItemsOut (below) is that ItemHistory adds 3 columns that ItemsOut does not have. Other than that table the SQL statements are the same (as you can see).
    SELECT Inv.AreaNo, Inv.CatType, Inv.CatNo, Inv.ItemNo, Inv.NumAvail, Inv.NumTotal, Inv.Active,
    IO.AID, IO.NumOut, IO.DateOut, IO.WorkerOut, '1' AS NumIn, '1/1/1900' AS DateIn, '1' AS WorkerIn,
    CC.CatID, CC.CatName, CC.BinItem, CC.Active, OG.LASTNAME, OG.FIRSTNAME, OG.MIDDLENAME
    FROM ItemInventory AS Inv
    LEFT JOIN CatCodes AS CC ON Inv.AreaNo = CC.AreaNo AND Inv.CatType = CC.CatType AND Inv.CatNo = CC.CatNo
    LEFT JOIN ItemsOut AS IO ON Inv.AreaNo = IO.AreaNo AND
    Inv.CatType = IO.CatType AND Inv.CatNo = IO.CatNo AND
    Inv.ItemNo = IO.ItemNo
    LEFT JOIN OGL..D.LE AS OG ON AID = OG.PK
    WHERE Inv.AreaNo = 0 AND Inv.CatType = 0
    As a test I tried just running an SQL statement against ItemsHistory and the Oracle table, thinking it might be something with ItemsHistory, but the following command also runs just fine:
    SELECT ItemHistory.*, OG.LASTNAME, OG.FIRSTNAME, OG.MIDDLENAME
    FROM ItemHISTORY
    LEFT JOIN OGL..D.LE AS OG ON AID = OG.PK
    I'm not sure why the one SQL statement is erroring out with ORA-01403. I see no problems with it, as it is the same as the one that works except using a different table, and another SQL statement using the table in the erroring SQL works also. I'm stumped!
    I am using the 'OraOLEDB.Oracle' provider in SQL 2005.
    Thanks for any help you can give on this...

    I've been testing it, and I've found that if I comment out 4 fields from the field list (all from the same table), it runs. As soon as I add any one of the 4 fields back into the select list, I get the Oracle error. I also found that I had to change the Oracle table from a LEFT JOIN to just a JOIN, or else I also get the Oracle error.
    Here is the SQL (same as the previous post) with the 4 fields commented out, and the modified JOIN. Maybe that will give someone an idea, because it has me puzzled...
    SELECT Inv.AreaNo, Inv.CatType, Inv.CatNo, Inv.ItemNo, Inv.NumAvail, Inv.NumTotal, Inv.Active,
    IO.AID, IO.NumOut, IO.DateOut, IO.WorkerOut, IO.NumIn, IO.DateIn, IO.WorkerIn,
    OG.LASTNAME, OG.FIRSTNAME, OG.MIDDLENAME
    --, CC.CatID, CC.CatName, CC.BinItem, CC.Active
    FROM ItemInventory AS Inv
    LEFT JOIN CatCodes AS CC ON Inv.AreaNo = CC.AreaNo AND Inv.CatType = CC.CatType AND Inv.CatNo = CC.CatNo
    LEFT JOIN ItemHistory AS IO ON Inv.AreaNo = IO.AreaNo AND Inv.CatType = IO.CatType AND Inv.CatNo = IO.CatNo AND
    Inv.ItemNo = IO.ItemNo
    JOIN OGL..D.LE AS OG ON AID = OG.PK
    WHERE Inv.AreaNo = 0 AND Inv.CatType = 0

  • Is possible use licence from ms sql 2014 std to ms sql 2012 standard ?

    We have bought licenses for mssql 2014 standart, but i need install mssql 2012 server std (must be version 2012). Is possible downgrade from sql server 2014 to 2012 ?? Is there any alternative way, how to legally use mssql 2012 server with licence of
    2014 ?
    Thank you

    Hi,
    Yes downgrade rights are there but you must speak to Licensing specialist.
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Wiki Article
    MVP

  • Using features from Microsoft Office with Java

    I have as a school project been given the task, to make a small program that can scan the HD for .doc files, from the criterias: -auther -date created -comments -Full text search ( for words or phrase in the raw text in the document )
    Is it possible from a java program, to acces the search functionallity in word itself ? Or do i have to find another way to get around this problem - like reading the doc as a bit stream.
    If it were possible to make use of the eksisting functions in word, it would be alot easyer to get this program done...
    Anyone who have any advise, please speak up...

    try this link
    http://jakarta.apache.org/poi/hdf/index.html

  • Calling Operating System Commands from PL/SQL using java

    Calling Operating System Commands from PL/SQL - The Java Way
    wlth help of given thread link,
    Calling OS Commands from Plsql
    but i had user privilege problem
    Declare
    x Varchar2(2000);
    Begin
    x := OSCommand_Run('/tmp/sri/GROUP_ho.sh');
    DBMS_OUTPUT.Put_Line(x);
    End;
    o/p;
    can't exec: /tmp/sri/GROUP_ho.sh lacks user privilege
    i done the grant privillage also
    part
    dbms_java.grant_permission('abcd', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    dbms_java.grant_permission('abcd', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    dbms_java.grant_permission('
    abcd', 'SYS:java.io.FilePermission','<<ALL FILES>>', 'execute');
    again
    get
    can't exec: /tmp/sri/GROUP_ho.sh lacks user privilege
    same error;

    Process management at the OS level should prevent execution continuing in the calling code until the command has completed (either successfully or with error).
    If the low level java code were to spawn child process threads then execution could continue, but I'm guessing the Java function your talking about doesn't do that and just calls the operating system to execute the command and waits for the returning code to come back.

  • Retrieving table of table in java from PL-SQL

    I want to transfer table or record from pl-sql to java. I mean I have a result set copied into a table row type variable. I will appreciate if any one can any one share some info or chunk of code on this.
    Thanks
    Ratan

    user529557,
    You have the following options:
    * Web Services
    * Servlets
    * EJB
    * RMI
    * JMS
    There may be others.
    Good Luck,
    Avi.

  • PL/SQL and Java implementation

    Hi all,
    We need to implement a fast solution for reporting to our existing web application. Application is totally based on stored procedures written in PL/SQL.
    We have already java classes for drawing different types of charts
    named Chartdirector (http://www.advsofteng.com/)
    This library can create chart images in memory.
    I have already read about calling java classes from PL/SQL and SQLJ too.
    My questions are;
    1. Is this safe to include classes to database and create
    reports by using loadjava in real life. I mean not in theory, in real life?
    2. Is there any experiments of the audience about this method?
    3. Would it be any performance problems about this?
    4. Should i prefer to use any Java container and jsps instead of this method?
    I will continue to research for necessary steps after i could see the light :)
    Thank you to all,
    Regards,
    Gokhan

    > 1. Is this safe to include classes to database and create
    reports by using loadjava in real life. I mean not in theory, in real life?
    Yes.
    > 2. Is there any experiments of the audience about this method?
    Experiments and actual implementation - yes. It works. Granted, it does not always work as easy as running the Java code from the command line. But it does work.
    > 3. Would it be any performance problems about this?
    This is a potential problem with any software code.
    4. Should i prefer to use any Java container and jsps instead of this method?
    To be honest, I prefer not using Java for web graphics as I'm not impressed with the quality and flexibility of the graphs generated. I prefer using (and paying for commercial use) for the JPGraph classes for PHP - and using that from PL/SQL (via Zend Core for Oracle).
    Another option is to use SVG and generated SVG directly from PL/SQL. But this requires a browser plugin and SVG also does not look that great. (this is btw what Oracle's HTMLDB does and uses)

  • Access a web service from pl/sql

    I am trying to access a web service from pl/sql. I have downloaded the code from
    http://www.oracle.com/technology/tech/webservices/htdocs/samples/dbwebservice/DBWebServices_PLSQL.html
    But when I try to execute the sql, I am getting the following error:
    SQL> @local.sql
    Package created.
    Package body created.
    No errors.
    BEGIN dbms_output.put_line(time_service.get_local_time('94065')); END;
    ERROR at line 1:
    ORA-29273: HTTP request failed
    ORA-06512: at "SYS.UTL_HTTP", line 1022
    ORA-12545: Connect failed because target host or object does not exist
    ORA-06512: at "WEB.DEMO_SOAP", line 71
    ORA-06512: at "WEB.TIME_SERVICE", line 15
    ORA-06512: at line 1
    It is failing at:
    resp := demo_soap.invoke(req,
    'http://www.ripedev.com/webservices/LocalTime.asmx',
    'http://ripedev.com/xsd/ZipCodeResults.xsd/LocalTimeByZipCode');
    But in the examples that I got from downloading source code, site used was:
    'http://www.alethea.net/webservices/LocalTime.asmx',
    'http://www.alethea.net/webservices/LocalTimeByZipCode');
    This site was not accessible. So I changed to the working site as follows, but still I
    am getting the above error.
    But I can access this site, if I type in the above address in the address bar of IE.
    Can any body help?
    I have oracle9i client installed on my machine and able to connect to server thru toad and sql plus.
    or IF any body refers me to a good website for the topic of "using webservies from pl/sql" that would be great too!

    Here is the complete code:
    time_service:
    CREATE OR REPLACE PACKAGE time_service AS
    FUNCTION get_local_time(zipcode IN VARCHAR2) RETURN VARCHAR2;
    END;
    CREATE OR REPLACE PACKAGE BODY time_service AS
    -- Location of Web service definition
    -- http://www.alethea.net/webservices/LocalTime.asmx?WSDL
    -- http://www.ripedev.com/webservices/LocalTime.asmx?WSDL
    -- http://www.xmethods.com/sd/2001/CurrencyExchangeService.wsdl
    --'http://ripedev.com/xsd/ZipCodeResults.xsd/LocalTimeByZipCode style=document');
    FUNCTION get_local_time(zipcode IN VARCHAR2) RETURN VARCHAR2 IS
    req demo_soap.request;
    resp demo_soap.response;
    BEGIN
    dbms_output.put_line('before new request..');
    req := demo_soap.new_request('LocalTimeByZipCode',
    'xmlns="http://ripedev.com/xsd/ZipCodeResults.xsd"');
    dbms_output.put_line('before add param..');
    demo_soap.add_parameter(req, 'ZipCode', 'xsd:string', zipcode);
    dbms_output.put_line('before invoke..');
    resp := demo_soap.invoke(req,
    'http://www.ripedev.com/webservices/LocalTime.asmx',
    'http://ripedev.com/xsd/ZipCodeResults.xsd/LocalTimeByZipCode');
    dbms_output.put_line('before return..');
    RETURN demo_soap.get_return_value(resp, 'LocalTimeByZipCodeResult',
    'xmlns="http://www.ripedev.com/webservices/"');
    END;
    BEGIN
    dbms_output.put_line('inside main time_service..');
    END;
    show errors
    SET serveroutput ON
    exec dbms_output.put_line(time_service.get_local_time('94065'));
    Here is demo_soap.sql:
    Rem
    Rem $Header: soapdemo.sql 21-may-2002.13:48:17 rpang Exp $
    Rem
    Rem soapdemo.sql
    Rem
    Rem Copyright (c) 2002, Oracle Corporation. All rights reserved.
    Rem
    Rem NAME
    Rem soapdemo.sql - <one-line expansion of the name>
    Rem
    Rem DESCRIPTION
    Rem A PL/SQL demo package for making SOAP RPC calls.
    Rem
    Rem NOTES
    Rem This demo package can only be used in oracle 9ir2. It utilizes 9iR2's
    Rem XDB (XMLType and HttpUriType) and 9iR1's enhancements to UTL_HTTP to
    Rem make SOAP RPC calls.
    Rem
    Rem MODIFIED (MM/DD/YY)
    Rem rpang 05/21/02 - created
    Rem
    Rem A PL/SQL demo package that makes a SOAP RPC calls.
    Rem
    CREATE OR REPLACE PACKAGE demo_soap AS
    /* A type to represent a SOAP RPC request */
    TYPE request IS RECORD (
    method VARCHAR2(256),
    namespace VARCHAR2(256),
    body VARCHAR2(32767));
    /* A type to represent a SOAP RPC response */
    TYPE response IS RECORD (
    doc xmltype);
    * Create a new SOAP RPC request.
    FUNCTION new_request(method IN VARCHAR2,
    namespace IN VARCHAR2)
    RETURN request;
    * Add a simple parameter to the SOAP RPC request.
    PROCEDURE add_parameter(req IN OUT NOCOPY request,
    name IN VARCHAR2,
    type IN VARCHAR2,
    value IN VARCHAR2);
    * Make the SOAP RPC call.
    FUNCTION invoke(req IN OUT NOCOPY request,
    url IN VARCHAR2,
    action IN VARCHAR2) RETURN response;
    * Retrieve the sipmle return value of the SOAP RPC call.
    FUNCTION get_return_value(resp IN OUT NOCOPY response,
    name IN VARCHAR2,
    namespace IN VARCHAR2) RETURN VARCHAR2;
    END;
    show errors
    CREATE OR REPLACE PACKAGE BODY demo_soap AS
    FUNCTION new_request(method IN VARCHAR2,
    namespace IN VARCHAR2)
    RETURN request AS
    req request;
    BEGIN
    req.method := method;
    req.namespace := namespace;
    RETURN req;
    END;
    PROCEDURE add_parameter(req IN OUT NOCOPY request,
    name IN VARCHAR2,
    type IN VARCHAR2,
    value IN VARCHAR2) AS
    BEGIN
    req.body := req.body ||
    '<'||name||' xsi:type="'||type||'">'||value||'</'||name||'>';
    END;
    PROCEDURE generate_envelope(req IN OUT NOCOPY request,
                   env IN OUT NOCOPY VARCHAR2) AS
    BEGIN
    env := '<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/1999/XMLSchema">
    <SOAP-ENV:Body><'||req.method||' '||req.namespace||'
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'||
    req.body||'</'||req.method||'></SOAP-ENV:Body></SOAP-ENV:Envelope>';
    END;
    PROCEDURE show_envelope(env IN VARCHAR2) AS
    i pls_integer;
    len pls_integer;
    BEGIN
    i := 1; len := length(env);
    WHILE (i <= len) LOOP
    dbms_output.put_line(substr(env, i, 60));
    i := i + 60;
    END LOOP;
    END;
    PROCEDURE check_fault(resp IN OUT NOCOPY response) AS
    fault_node xmltype;
    fault_code VARCHAR2(256);
    fault_string VARCHAR2(32767);
    BEGIN
    fault_node := resp.doc.extract('/soap:Fault',
    'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/');
    IF (fault_node IS NOT NULL) THEN
    fault_code := fault_node.extract('/soap:Fault/faultcode/child::text()',
         'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/').getstringval();
    fault_string := fault_node.extract('/soap:Fault/faultstring/child::text()',
         'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/').getstringval();
    raise_application_error(-20000, fault_code || ' - ' || fault_string);
    END IF;
    END;
    FUNCTION invoke(req IN OUT NOCOPY request,
    url IN VARCHAR2,
    action IN VARCHAR2) RETURN response AS
    env VARCHAR2(32767);
    http_req utl_http.req;
    http_resp utl_http.resp;
    resp response;
    BEGIN
    generate_envelope(req, env);
    -- show_envelope(env);
    http_req := utl_http.begin_request(url, 'POST','HTTP/1.0');
    utl_http.set_header(http_req, 'Content-Type', 'text/xml');
    utl_http.set_header(http_req, 'Content-Length', length(env));
    utl_http.set_header(http_req, 'SOAPAction', action);
    utl_http.write_text(http_req, env);
    http_resp := utl_http.get_response(http_req);
    utl_http.read_text(http_resp, env);
    utl_http.end_response(http_resp);
    resp.doc := xmltype.createxml(env);
    resp.doc := resp.doc.extract('/soap:Envelope/soap:Body/child::node()',
    'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"');
    -- show_envelope(resp.doc.getstringval());
    check_fault(resp);
    RETURN resp;
    END;
    FUNCTION get_return_value(resp IN OUT NOCOPY response,
    name IN VARCHAR2,
    namespace IN VARCHAR2) RETURN VARCHAR2 AS
    BEGIN
    RETURN resp.doc.extract('//'||name||'/child::text()',
    namespace).getstringval();
    END;
    END;
    show errors

  • File Deletion from PL/SQL using Java

    I'm able to delete a file on the OS from PL/SQL by calling a java class. But there is a problem if I am trying to delete any file located on any machine othere than the one on which the Database is hosted.
    Can anyone tell me how delete a file which is on anothere machin using PL/SQL with Java ?

    You can use a FTP Call: http://www.savarese.org/oro/software/NetComponents.html

  • Help using Java to retrieve XMLType returned from PL/SQL stored object

    Hi,
    Please bear with me if this is a trivial question. I'm brand new to Java, JDBC, and XML DB. I've been spinning my wheels on this for a few hours now.
    I have a table:
    XMLDB_USER@xmldb64> desc my_test_table
    Name                                      Null?    Type
    ID                                                 NUMBER(9)
    DOC                                                SYS.XMLTYPE(XMLSchema "http:
                                                        //www.myproquest.com/Global_
                                                        Schema_v3.0.xsd" Element "RE
                                                        CORD") STORAGE BINARYI've written a trivially simple PL/SQL function to retrieve the DOC column, based on the ID passed to it.
    create or replace function get_doc(goid in number) return xmltype is
      doc_content xmltype;
    begin
      select doc into doc_content from my_test_table where id = goid;
      return doc_content;
    end;
    /Up to here, everything works fine. I wrote a small anonymous PL/SQL block, and proved that I can call the PL/SQL function successfully.
    Now, I want to implement in Java. This is where I get confused.
    Currently my code looks like this:
    import java.sql.*;
    import oracle.jdbc.*;
    import oracle.jdbc.OracleTypes;
    import oracle.jdbc.pool.OracleDataSource;
    import oracle.xdb.*;
    import java.io.*;
    import java.lang.StringBuilder;
    import java.sql.Clob;
    class MyJava
      public static void main(String args[]) throws SQLException, IOException
        Clob xml = null;
        System.out.print("Connecting to the database...");
        System.out.flush();
        OracleDataSource ods = new OracleDataSource();
        String URL = "jdbc:oracle:thin:@//pqhdb201.aa1.pqe:1522/xmldb64";
        ods.setURL(URL);
        ods.setUser("xmldb_user");
        ods.setPassword("xmldb_user");
        Connection conn = ods.getConnection();
        System.out.println("connected.");
        System.out.println("GOID to be retrieved is " + args[0]);
        CallableStatement cs1 = null;
    try {
        cs1 = conn.prepareCall( "{? = call get_doc (?)}" );
        cs1.registerOutParameter(1,OracleTypes.OPAQUE,"XMLType");
        cs1.setString(2,args[0]);
        cs1.execute();
    //    xml = XMLType.createXML(cs1.getOPAQUE(1));
        xml = (Clob) cs1.getObject(1);
    //    System.out.println(((XMLType)xml).getStringVal());
    //    System.out.println(xml.getClobVal());
        System.out.println(xml.getCharacterStream());
      finally {
         if(cs1!=null) cs1.close();
         if(conn!=null) conn.close();
    }This compiles, but when I run, I get:
    pqhdb201:[xmldb64]:(/home/oracle/xmldb_scripts):$java MyJava 91455713
    Connecting to the database...connected.
    GOID to be retrieved is 91455713
    Exception in thread "main" java.sql.SQLException: invalid name pattern: XMLDB_USER.XMLType
            at oracle.jdbc.oracore.OracleTypeADT.initMetadata(OracleTypeADT.java:553)
            at oracle.jdbc.oracore.OracleTypeADT.init(OracleTypeADT.java:469)
            at oracle.sql.OpaqueDescriptor.initPickler(OpaqueDescriptor.java:237)
            at oracle.sql.OpaqueDescriptor.<init>(OpaqueDescriptor.java:104)
            at oracle.sql.OpaqueDescriptor.createDescriptor(OpaqueDescriptor.java:220)
            at oracle.sql.OpaqueDescriptor.createDescriptor(OpaqueDescriptor.java:181)
            at oracle.jdbc.driver.NamedTypeAccessor.otypeFromName(NamedTypeAccessor.java:83)
            at oracle.jdbc.driver.TypeAccessor.initMetadata(TypeAccessor.java:89)
            at oracle.jdbc.driver.T4CCallableStatement.allocateAccessor(T4CCallableStatement.java:689)
            at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:157)
            at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:202)
            at oracle.jdbc.driver.OracleCallableStatementWrapper.registerOutParameter(OracleCallableStatementWrapper.java:1356)
            at MyJava.main(MyJava.java:29)As you can see from the commented lines, I've tried several different approaches, based on various examples from Oracle documentation and various samples found on the net. My problem, I think, is that I have a fundamental disconnect somewhere. Objects? Types? Different methods? getClobVal? getStringVal? getCharacterStream? I'm still trying to get up to speed on all the lingo and terminology, and, as a result, I suspect I'm asking the wrong questions, and getting wrong results.
    Based on the simple example above, my table and PL/SQL function definitions, can someone help me fill in the gaps of what I'm missing in terms of the Java code?
    Thanks!
    -Mark

    Hi, I´ve been working on an application that return an XMLTYPE from an schema package, the XML is generated in a query, not read it in a table, and use that variable in a JSP.
    The DDL of the package function is this:
    CREATE OR REPLACE
    PACKAGE BODY pkg_modulos
    IS
        FUNCTION obtenerModulos (pAnio IN NUMBER DEFAULT 2011)
            RETURN XMLTYPE
        IS
            x    XMLTYPE;
        BEGIN
            SELECT  XMLELEMENT ("tree", XMLAttributes (0 AS "id"),
                        (SELECT  DBMS_XMLGEN.getxmltype(DBMS_XMLGEN.newcontextfromhierarchy('SELECT level,
                                              XMLElement("item",
                                                                          XMLAttributes(
                                                                    m.idmodulo as "id",
                                                                    m.nombre AS "text"))
                                FROM            modulos m
                 WHERE m.anio = 2011
    CONNECT BY   PRIOR m.idmodulo = m.padre
    START WITH   m.padre IS NULL'))
                            FROM     DUAL))
                            arbolXML
              INTO  x
              FROM  DUAL;
            RETURN x;
        END;                                                                         
    END;   as far as I see there shouldn´t be any problems with this code
    The problem is on the JSP code
    this is my code:
    <?xml version="1.0" encoding="UTF-8"?>
    <%@ page contentType="text/xml; charset=UTF-8" import="java.io.*,java.lang.*,java.sql.*,java.util.*,oracle.jdbc.*,oracle.xdb.*, oracle.jdbc.OracleTypes,oracle.jdbc.pool.OracleDataSource"%>
    <%
      Connection dbconn;
      OracleDataSource ods = new OracleDataSource();
      OracleCallableStatement stmt;
        try
             String hostname="localhost";
             String dbname="xe";
             String usr="seguridad";
             String pass="seguridad";
             String URL = "jdbc:oracle:thin:@"+hostname+":1521:"+dbname;
             ods.setURL(URL);
            ods.setUser(usr);
            ods.setPassword(pass);
             dbconn = ods.getConnection();
              String st=request.getParameter("st").toString();
              int np=Integer.parseInt(request.getParameter("np").toString());     
              stmt = (OracleCallableStatement)dbconn.prepareCall( "begin ? := "+st+"; end;" );
              stmt.registerOutParameter(1,OracleTypes.OPAQUE,"SYS.XMLTYPE");          
              stmt.execute();
              XMLType xml = null;
              xml = (XMLType) stmt.getObject(1);
              System.out.println(xml.getStringVal());
              stmt.close();
              dbconn.close();
        catch (SQLException s)
          out.println("SQL Error: " + s.toString());
           System.out.println("SQL Error: " + s.toString());
    %>I´m getting te error:
    SQL Error: java.sql.SQLException: inconsistent java and sql object types: SYS.XMLTYPE
    Making a debbuging I identified that the exception is been raised in this line:
    xml = (XMLType) stmt.getObject(1);I´ve been checking a lot of online documentation but I´ve not been able to make it work
    If anyone could help me please, I don´t know what else to do
    Thanks... sorry for the english

  • Generating next number from the SQL database using java

    Hi friends, I have a problem and need your help. I am working on a project about submitting claims form through the adobe PDF file and SQL database. I have problem working on a web service (written in java) that will generate the next Invoice Number from the SQL Database table. The field type for the column is text(var char). *Example: I first need to get into the table and search for the last Invoice number in the table and if the last invoice number in the table from the database is 3, i would want to generate the next number which is 4 and filled it up in the PDF file through web service that i am implementing. Can you all provide me some guidelines on how to implement this method in my web service?
    Thanks a lot. I need it by today. Hope someone can reply this as soon as possible.
    Lim89
    Edited by: LIM89 on Apr 2, 2008 7:10 PM

    far simpler to use a sequence generator, which most databases support.
    Suggested method to get the max value in the column is NOT secure, unless you lock the entire table for update before you do so, which is a severe performance penalty.

Maybe you are looking for

  • Invalid data found when base64 decoding a String

    When I tried to start my server, my server stops automatically. Following are my server0 logs when the server0 stopped automatically when I tried to start my WEB-AS. <!LOGHEADER[START]/> <!HELP[Manual modification of the header may cause parsing prob

  • Maximum memory size (Seriennummer  W8######AGU)

    My MacBook Pro (Seriennummer  W8######AGU). Mid 2010 What is the maximum size of memory which can be installed? Regards Desmond <Edited by Host>

  • Satellite L350 and OpenGL 1.4

    I have seen similar posts in the past, but none of them could help me with my issue. Background, I have a Satellite L350 with Windows Vista and try to run a game that needs OpenGL 1.4. I already installed the current display drivers from this site bu

  • How do I get a refund?

    I bought a movie and checked the box to watch it on my ipad.  It won't stay on my ipad.  When ever I unplug myipad from my mac the movie disappears, even though I check the box to put I on my ipad.  I bought the movie to watch while in travel, but co

  • Can COLMAP call a User Defined Function?

    Hi, I'm new to GoldenGate. We are replicating many source databases into a single target database. All source databases have the same schema but with different data. I need to generate a GUID to insert into a new column in every table in the source d