Solved

passing multiple records from java to oracle procedure

Posted on 2002-05-27
5
1,329 Views
Last Modified: 2012-06-27
i want to pass multiple records from java to oracle procedures.
how to do it
will pl/sql tables help??
if yes then how to populate pl/sql tables from java
0
Comment
Question by:shaileshpaldiwal
5 Comments
 
LVL 47

Expert Comment

by:schwertner
ID: 7037171
Program
-------

import java.sql.*;
import java.io.*;
import java.util.*;
import java.math.BigDecimal;
import oracle.sql.*;
import oracle.jdbc.driver.*;

public class callInOutArray extends Object {

/*
   This program demonstrates how to emulate calling a stored procedure
   with PL/SQL table parameters via JDBC.  You cannot call a PL/SQL table
   parameter directly, but you can use an Object of Type Table.

   The Script used to create the procedure used in this example is as
   follows:

   create or replace type tabtype as table of varchar2(30);
   /

   create or replace package ioArray as

   procedure testproc(iotab in out tabtype,otab out tabtype);

   end ioArray;
   /

   create or replace package body ioArray as

   procedure testproc(iotab in out tabtype,otab out tabtype) is
   begin
      otab := iotab;
      if iotab.count = 0 then
         iotab.extend;
         iotab(1) := 'Record 1';
      else
         iotab.extend;
         iotab(iotab.count) := 'Second'||iotab(1);
      end if;
   end testproc;
   end ioArray;
   /
*/
   public static void main(String[] args) throws SQLException {
      DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    // Connect to the database

      Connection conn =
         DriverManager.getConnection ("jdbc:oracle:oci8:@S692815.WORLD",
                                   "scott", "tiger");

   //  First, declare the data arrays that will store the data.

      String [] p1obj = {"First"};
      String [] p2obj = {};

   //  Now, declare a descriptor to associate the host array type with the
   //  array type in the database.

      ArrayDescriptor desc1=ArrayDescriptor.createDescriptor("TABTYPE",conn);

   //  Create the ARRAY objects to associate the host array
   //  with the database array.

      ARRAY p1arr = new ARRAY(desc1,conn,p1obj);
      ARRAY p2arr = new ARRAY(desc1,conn,p2obj);

   //  Declare the callable statement.
   //  This must be of type OracleCallableStatement to use:
   //     setArray(ARRAY)
   //         and
   //     registerOutParameter(position,type,oracletype)

      OracleCallableStatement ocs =
         (OracleCallableStatement)conn.prepareCall("{call ioarray.testproc(?,?)}");

   //  The first parameter is in out, so you must use setArray to
   //  pass it to the statement.

      ocs.setArray(1,p1arr);

   //  The first parameter is in out, so you must Register the parameter as
   //  well.
   //  Note the reuse of the TYPE.

      ocs.registerOutParameter(1,OracleTypes.ARRAY,"TABTYPE");

  //   The second parameter is out, so that must be registered too.
  //   Note the reuse of the TYPE.

      ocs.registerOutParameter(2,OracleTypes.ARRAY,"TABTYPE");

   //  Execute the procedure

      ocs.execute();

   //  Associate the returned arrays with the ARRAY objects.

      p1arr = (ARRAY)ocs.getArray(1);
      p2arr = (ARRAY)ocs.getArray(2);

   //  Get the data back into the data arrays.

      p1obj = (String[])p1arr.getArray();
      p2obj = (String[])p2arr.getArray();

   //  Show the results:

      System.out.println("p1obj[p1obj.length-1] is " + p1obj[p1obj.length-1]);
      System.out.println("p2obj[0] is " + p2obj[0]);

   }
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7037363
I have deleted the duplicate question.

Computer101
E-E Moderator
0
 

Author Comment

by:shaileshpaldiwal
ID: 7037669
this works for j2se 1.4
but what about jdk 1.3
is there any subsitute for this in jdk 1.3
0
 
LVL 5

Expert Comment

by:jpkemp
ID: 9016985
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ'ed and points refunded
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
jpkemp
EE Cleanup Volunteer
0
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9114455
Question is PAQ'd and points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle Database Upgrade 13 62
EXECUTE IMMEDIATE 5 53
query in Oracle forms Builder 2 41
ORA-12560: TNS:protocol adapter error 8 83
Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now