Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / December 2003

Tip: Looking for answers? Try searching our database.

Q: PL*SQL stored procedure, oracle objects and Java

Thread view: 
Abraham Leolo - 14 Dec 2003 21:43 GMT
Hello,

I've googled hours for detailed information on this topic, but both the
Oracle technical network as well as Google have let me down.

The situation is that I get a resultset (a cursor) from a stored
procedure, but this resultset (a nested table) contains objects created
in PL*SQL.
My question is simple, how to access these objects within the resultset
from Java ?

---

Example:

Calling a PL*SQL stored procedure from Java just like this, which in
this example returns a simple address as string.

     // Declare the callable statement
     CallableStatement cstmt;

     // Declare the command syntax with placeholders
     String command = "{call PERSMGT.GETADDRESS(?)}";

     // Make the command into a callable statement
     cstmt = con.prepareCall(command);

     // Initialize command variables
     cstmt.registerOutParameter(1, Types.VARCHAR);

     // Execute the command
     cstmt.execute();

     // Retrieving Stored Procedure results
     String address = cstmt.getString(1);

     // Close the Callable Statement
     cstmt.close();

My question is how to access the returned address(es) if the returned
result is not VARCHAR but a nested table of objects like the one shown
below.

CREATE TYPE Address AS OBJECT (
    AddrStreet Varchar2(50),
    AddrCity Varchar2(30),
    AddrZip Number,
    AddrCountry Varchar2(10) );

Which type of cstmt.registerOutParameter() is this, and after execution,
how do I access this nested table WITH objects in it? My real problem is
to access the objects within the result. Does anybody know how to do
that? A complete example and source would be very helpful. Thanks in
advance.

Cheers
Abraham
Bjorn Abelli - 15 Dec 2003 01:06 GMT
"Abraham Leolo" wrote...

> The situation is that I get a resultset (a cursor)
> from a stored procedure, but this resultset (a nested
> table) contains objects created in PL*SQL.
> My question is simple, how to access these objects
> within the resultset from Java ?

I haven't tried it myself, but I found an article on Oracle Technology
Network that seems promising.

http://otn.oracle.com/sample_code/tech/java/codesnippet/jdbc/objects/ObjectTypes.html

If the above line wraps, this link should work:

 http://tinyurl.com/z8oy

If that doesn't help you, there's always another approach that I've seen
many Oracle developers use in the past for different obstacles. Simply
create a "wrapping procedure" that returns a "modified cursor" with only
"plain" types, that is, to "expand the objects" to plain types already in a
procedure at the Oracle Server. That approach should also make your code on
the client-side more portable...

For what it's worth, I hope my first suggestion really helps, as I probably
have to look into something similar next year...

// Bjorn A
Abraham Leolo - 16 Dec 2003 09:14 GMT
Thanks for the hint, but the problem isn't yet solved.

It further it led me to an article where accessing nested tables seems
to work with Oracle 9i, since you can create Java objects within the DB.

http://asktom.oracle.com/pls/ask/f?p=4950:8:1320383202207153292::NO::F4950_P8_DI
SPLAYID,F4950_P8_CRITERIA:8908169959941
,

Unfortunately I am using Oracle 8i and I haven't found any way to access
nested tables without creating Java objects in the DB, which is only
supported by 9i. Though I am using Java and JDBC to access the DB I
cannot create Java objects inside the DB in the first place.

Accessing PL*SQL generated objects that reside within the nested table
would be my next problem but Oracle 8i and JDBC seem to quit with the
nested tables already. I'm going to do the PL*SQL logic in Java and just
fire some SELECTs over JDBC to the DB, since I don't see any other way
around this issue.

cheers,
Abraham

> I haven't tried it myself, but I found an article on Oracle Technology
> Network that seems promising.
[quoted text clipped - 16 lines]
>
> // Bjorn A
Jeff Smith - 15 Dec 2003 13:05 GMT
http://sales.esicom.com/sales/oracle/java.816/a81354/oraoot.htm#1000888

Retrieving has never been a problem, but pushing them has been due to
connection pooling problems.

> Hello,
>
[quoted text clipped - 53 lines]
> Cheers
> Abraham


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.