How to Pass String array from Java to PL/SQL and this use in CURSOR
hi,
I cant understand how to pass Array String as Input Parameter to the Procedure and this array use in Cursor for where condition like where SYMPTOM in( ** Array String **).
This array containing like (SYMPTOM ) to be returned from the java to the
pl/sql (I am not querying the database to retrieve the information).
I cannot find an example on this. I will give the PL/SQL block
create or replace procedure DISEASE_DTL<*** String Array ***> as
v_SYMPTOM number(5);
CURSOR C1 is
select distinct a.DISEASE_NAME from SYMPTOM_DISEASE_RD a
where ltrim(rtrim(a.SYMPTOM)) in ('Fever','COUGH','Headache','Rash') ------- ***** Here use this array element(like n1,n2,n3,n4,n5..) ******
group by a.DISEASE_NAME having count(a.DISEASE_NAME) > 3 ----------- ***** 3 is no of array element - 1 (i.e( n - 1))*****
order by a.DISEASE_NAME ;
begin
for C1rec IN C1 loop
select count(distinct(A.SYMPTOM)) into v_SYMPTOM from SYMPTOM_DISEASE_RD a where A.DISEASE_NAME = C1rec.DISEASE_NAME;
insert into TEMP_DISEASE_DTLS_SYMPTOM_RD
values (SL_ID_SEQ.nextval,
C1rec.DISEASE_NAME,
(4/v_SYMPTOM), --------**** 4 is no of array element (n)************
(1-(4/v_SYMPTOM)));
end loop;
commit;
end DISEASE_DTL;
Please give the proper solution and step ..
Thanking you,
Asish
I've haven't properly read through your code but here's an artificial example based on a sql collection of object types - you don't need that, you just need a type table of varchar2 rather than a type table of oracle object type:
http://orastory.wordpress.com/2007/05/01/upscaling-your-jdbc-app/
Similar Messages
-
Passing String Array from Java to PL/SQL
Hi,
We are having couple of packages which have been written in PL/SQL . I would like to know how i can send arrays as input parameters from Java to any stored proc in Oracle. I am having Oracle 8i as the DB and am using Websphere RSA for deployment purposes.
please find below Java , PL/SQL code and exception
PL/SQL Code :
PACKAGE PKG_SURCHARGE
IS
TYPE commodity_key IS TABLE OF VARCHAR2(500) INDEX BY BINARY_INTEGER;
PROCEDURE RETRIEVE_CHARGES
in_Commodity_tab IN commodity_key,
IS
BEGIN
dbms_output.put_line('in_Commodity_tab(' || '0' || ') : ' || in_Commodity_tab(0) );
Java Code :
CallableStatement cstmt=null;
Connection conn=null;
try{
conn=getConnection();
System.out.println("++++++connected");
String sqlStr = "{call Pkg_Surcharge.RETRIEVE_CHARGES(?) }";
cstmt = conn.prepareCall(sqlStr );
//1.
String[] javaArray={"20081117","20081117"};
ArrayDescriptor dateDescripter = ArrayDescriptor.createDescriptor( "commodity_key", conn );
oracle.sql.ARRAY dateArray = new oracle.sql.ARRAY(dateDescripter, conn, javaArray);
System.out.println("++++++registered-1");
Catch (Exception e){
e.printStackTrace();
Exception Occured:
java.sql.SQLException: Invalid Pattern Name <Schema Name>.commodity_key
Appreciate your help in this regard
Thanks
Srini
Edited by: [email protected] on Nov 25, 2008 4:55 AMAvi is correct. You must create a varray or nested table instead of using a PL/SQL index-by table.
SQL> create type commodity_key as varray(#) of varchar2(500);
or
SQL> create type commodity_key as table of varchar2(500);
Use the varray if you know the number of items in the array. Otherwise, use the nested table. -
Example of passing String Array from java to C using JNI
hi all
i searched net for passing string array from java to C but i dont get anything relevent
i have
class stu
int rollno
string name
String [] sub
i want to pass all as String array from java to C and access it C side1. Code it as though it were being passed to another method written in java.
2. Redefine the method implementation to say "native".
3. Run jnih to generate a C ".h" file. You will see that the string array
is passed into C as a jobject, which can be cast to a JNI array.
4. Write the C code to implement the method and meet the interface
in the generated .h file. -
Passing an array from Java to Pl/SQL Procdures
I am relatively new to the Java world and I am unable to pass back an array from Java back to the calling PL/SQL procedure. I have read many of the posts that deal with this issue and in specificly have viewed Ask Tom. My main issue is trying to get the data types matched up. I am able to return varchar2, numbers, and the like, but an array of filenames is not happening. I have tried a variety of "types" but unable to accomplish the task. Please help.
I have my Java class basically defined as:
public static oracle.sql.ARRAY[] getCollection(String directory)
throws SQLException
{ // provide a directory and get a listing of files
File path = new File( directory );
String[] list = path.list();
return list;
SQL Type and PL/SQL Procedure is:
CREATE OR REPLACE TYPE PTO_FILE IS TABLE OF VARCHAR2(100);
create or replace function get_dir_collection( p_directory in varchar2 ) RETURN PTO_FILE
as language java
name 'DirCollection.getCollection( java.lang.String ) return oracle.sql.ARRAY[]';
/I know that it is not an ARRAY. It is however an "array" and I am attempting to map Java's String[][ to some "object" on the oracle side. I have looked at the link you sited and was not able to find the data mapping. I have found that mapping data types between different "languages" is some of the most difficult aspects of working with multiple languages.
Any suggestions? Thanks -
How to add byte[] array based Image to the SQL Server without using parameter
how to add byte[] array based Image to the SQL Server without using parameter.I have a column in table with the type image in sql and i want to add image array to the sql image column like below:
I want to add image (RESIM) to the procedur like shown above but sql accepts byte[] RESIMI like System.Drowing. I whant that sql accepts byte [] array like sql image type
not using cmd.ParametersAdd() method
here is Isle() method contentSQL Server binary constants use a hexadecimal format:
https://msdn.microsoft.com/en-us/library/ms179899.aspx
You'll have to build that string from a byte array yourself:
byte[] bytes = ...
StringBuilder builder = new StringBuilder("0x", 2 + bytes.Length * 2);
foreach (var b in bytes)
builder.Append(b.ToString("X2"));
string binhex = builder.ToString();
That said, what you're trying to do - not using parameters - is the wrong thing to do. Not only it is insecure due to the risk of SQL injection but in the case of binary data is also inefficient since these hex strings are larger than the original byte[]
data. -
Passisng array from Java into PL/SQL procedure
Hi everybody!
I have type created with :
CREATE OR REPLACE TYPE my_type IS TABLE OF number;
Next I have procedure withinin a package which has parameters:
PROCEDURE my_proc
(p_Result OUT NUMBER,
p_Id table.column%TYPE,
p_MyType my_type
I call this procedure from Java :
import javax.sql.*;
import java.sql.*;
import oracle.jdbc.*;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
public class MyClass extends QueryClient {
private int Id;
private int type;
private Integer[] List;
private int result;
public MyClass(int Id, eType type,
Integer[] List) throws SQLException {
this.Id = Id;
this.type = (type.equals(eType.TYPE_EXPORT) ? 1 : 0);
this.List = List;
this.execute("{call my_package.my_proc(?,?,?,?)}");
public void body(CallableStatement stmt) throws SQLException {
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("MY_USER.MY_TYPE", getCon());
ARRAY array_to_pass = new ARRAY(descriptor, getCon(), this.List);
// register the type.
stmt.registerOutParameter(1, OracleTypes.NUMBER); // result of procedure calling
stmt.setInt(2, this.Id );
stmt.setInt(3, this.type);
stmt.setArray(4, array_to_pass);
// execute and retrieve the result set
stmt.execute();
this.result = stmt.getInt(1);
public int getResult() {
return result;
EVERYTHING WORKS FINE, BUT when I move type "my_type" into package header
TYPE my_type IS TABLE OF number;
I receive error after calling procedure
java.sql.SQLException: invalid name pattern: MY_USER.MY_TYPE
I dropped type my_type after moving it into package. So there is only one my_type, in the package.
User who call procedure is owner of the package.
So questions are:
1. Is it possible to have my_type within package without error?
2. Is it possible to describe my_type without having a connection to database? My aim is eliminate number of connections to database.
Thanks all.
Matus.You can't use the packaged type for this. You need to use the original collection type (i.e. via the CREATE TYPE syntax) as you have discovered yourself.
Regards -
Pass arrays from Java to PL/SQL procedure.
Hi All,
Can some body give an example, where an array of strings is passed from java to a PL/SQL procedure.
Any help in this regard is appreciated.
Thanks,
PrashantKiran Kumar Gunda wrote:
I would want to use Oracle provided (Oracle Extensions) API to pass arrays to PL/SQL
procedure from Java. I am using weblogic connection pool, but the 'createDescriptor'
method donot allow Pooled connection. So I have taken Physical Connection by casting
to 'WLConnection'. Now, weblogic strongly suggest NOT to use this,as pooling capabilities
will be disabled.
But by setting RemoveInfectedConnectionsEnabled to false, we can ask weblogic
to return the Physical Connection to Pool. I have tested this with the attached
code. I DON'T find any issue.Good. The only real risk to obtaining the physical connection is retaining and
using it beyond the current thread execution. Your code looks OK. The only thing
I'd suggest is to add to the finally block. I would put a separate try-catch-ignore
block around every action in the finally, so if one fails, the others are still
done.
As long as you're writing good JDBC like that, there is no risk to telling the
pool to trust the code, by setting RemoveInfectedConnectionsEnabled to false.
That way you'll retain all the performance of the pools.
Joe
>
I want your opinion in this, so that I will be confident in using this feature
in our application.
Note : Please look at the sample code that I am using. I AM NOT GOING TO USE PHYSICAL
CONNECTIONS for normal operations. I will use Physical Connection only when I
want to pass Arrays to Oracle.
Thanks
Kiran -
Pass 2D array from java to PLSQL
HI,
My requirement is that I have to pass dynamic parameters to be stored in a table. The table I have is
CODE || TAG_LABEL || TAG_COLMN_NAME
023 || Registration || CHAR_TAG1
023 || Agreement Number || NUM_TAG1
023 || Agency || NUM_TAG2
023 || Start Date || DATE_TAG1
this table A. gives me the list of all possible parametes
CODE || CHAR_TAG1 || CHAR_TAG2 || NUM_TAG1 || NUM_TAG2 .. ..
023 || 420/09 || -- || 100023 || 1002
021 || -- || 400030 || -- || --
023 || 450/10 || -- || 100025 || --
this table B gives the place where the values for this parameter has to be stored.So for code 023 if I have parameters say Registration='240/10' and start_date = '10/02/2010' then, how do I pass these dynamic paramters to the plsql and from there how do i handle storing this in my final Table B.
I searched the net for Dynamic sql and I am very basic in PLSQLs. Can anyone please help or atleast if there is a documentation that does exactly this, it would be very helpful.
Thanks
RacheFrom the pl/sql side you need to create your object types
create or replace type sample_array_obj
as object( firstitem varchar2(20 char),
seconditem varchar2(10 char)
create or replace
type sample_array_type is table of sample_array_objand then you need to grant execute access on both the object and type
grant execute on sample_array_obj to public;
grant execute on sample_array_type to public;you have to declare these to java then. (I'm not a java programmer, but the java then has to get its collection type from the database) -
Passing a structure from Java to PL/SQL Procedure
Environment: Oracle DB, Tomcat/Apache
How do we pass a structure (Table Record Type) from Java to a PL/SQL Stored Procedure?
We are doing JSP-->JavaClass/Bean to communicate to DB. We have an existing PL/SQL packages/Procedure to insert records into table (These procedures have record types as in/out parameters). So is there a way to call these from Java?
Thanks in advance.
RameshOracle9 i JDBC Developers Guide and Reference(page 21-16):
It is not feasible for Oracle JDBC drivers to support calling arguments or return
values of the PL/SQL RECORD, BOOLEAN, or table with non-scalar element types.
However, Oracle JDBC drivers support PL/SQL index-by table of scalar element
types. For a complete description of this, see "Accessing PL/SQL Index-by Tables"
on page 16-21.
As a workaround to PL/SQL RECORD, BOOLEAN, or non-scalar table types, create
wrapper procedures that handle the data as types supported by JDBC. For example,
to wrap a stored procedure that uses PL/SQL booleans, create a stored procedure
that takes a character or number from JDBC and passes it to the original procedure
as BOOLEAN or, for an output parameter, accepts a BOOLEAN argument from the
original procedure and passes it as a CHAR or NUMBER to JDBC. Similarly, to wrap a
stored procedure that uses PL/SQL records, create a stored procedure that handles
a record in its individual components (such as CHAR and NUMBER) or in a structured
object type. To wrap a stored procedure that uses PL/SQL tables, break the data
into components or perhaps use Oracle collection types. -
How To Pass an Array from One Frame in a Sequence to a ptr in the next Frame
I have an array (generated from the "Replace Array Subset" VI) that I
wish to pass to the next sequence in a frame.
In this second frame, however, the VI that this data will go into
expects it as a pointer to a buffer.
Of course in C, the array name is the pointer to the array itself, but
apparently this is not the case in Labview..
because if I wire the output array to the edge of the frame (Blue
solid blox - "Tunneling'?), and then try to connect
that blue box in the second frame, to the VI expecting a pointer and
the wire connection gets broken, and the blue
solid box goes empty.
How Can I do this??You are not being quite clear. If the next frame expects a pointer to a buffer, it cannot be a vi. Labview has no pointer types. You must be referring to a Call Library Node which is set up to call a DLL function. If this is the case, you need to configure the Call Library Node to accept an array of the data type. Then you can wire the array into the call library node.
Is this the case, Call Library Node?
- tbob
Inventor of the WORM Global -
How to pass int array as an IN parameter to PLSQL Procedure
Hi,
How to pass int array in java to a stored procedure througn jdbc
and what type of data type I should declare to this IN parameter
in PLSQL Procedure.
Thanks,
SimiHi,
The best way to do what you want depends on what you want. Start by describing what you need to do. It's best to post some sample data (CREATE TABLE and INSERT statments) and what results you want from that sample data. (See the forum FAQ: https://forums.oracle.com/message/9362002)
If you have ideas about how to do the job (e.g., populating a temporary table) it can be helpful to include those, too, but distinguish clearly between WHAT you need to do and HOW you might do it.
As Bencol suggested, a SYS_REFCURSOR might be the best way to pass back the results.
Since you didn't post your table, or even describe what you wanted to do with it, I'll illustrate using scott.emp, which is probably on your system.
Say you wanted a procedure that took a DATE as an argument, and returned a some designated columns (empno, ename and hiredate in the example below) for all employees hired on or after the given DATE. You might write a procedure like this:
CREATE OR REPLACE PROCEDURE hired_since
( start_date IN DATE
, out_data OUT SYS_REFCURSOR
AS
BEGIN
OPEN out_data FOR
SELECT empno, ename, hiredate
FROM scott.emp
WHERE hiredate >= start_date;
END hired_since;
SHOW ERRORS
You can test it in SQL*Plus like this:
VARIABLE c REFCURSOR
EXEC hired_since (DATE '1982-01-01', :c);
PRINT :c
The output I got from this test was:
EMPNO ENAME HIREDATE
7788 SCOTT 19-APR-87
7876 ADAMS 23-MAY-87
7934 MILLER 23-JAN-82 -
How to pass an object from jsp to other jsp using SendRedirect
How to pass an object from one jsp to the other jsp using ssendRedirect with out using the session
I am having 2 jsps
x.jsp and y.jsp
From x.jsp using sendRedirect iam going to y.jsp
From x.jsp i have pass an object to the y.jsp
Is it possible without putting the object in session
Is it possible using EncodeUrl
Please help me Its UrgentIs it possible without putting the object in sessionAnything is possible. Would you accept that it is very difficult?
When you send a redirect, it tells the browser to send a new request for the target page. That means any request parameters/attributes are lost.
Is it possible using EncodeUrl response.encodeURL() puts the session id into a url if the browser does not support cookies. It is purely for retaining the session.
There are two ways that you can communicate across a sendRedirect.
1 - use the session
2 - pass a parameter in the url.
parameters are string based, so passing objects is almost out of the question.
Potentially you could serialize your object, encode it in base64 (so it is composed completely as characters) and pass it as a parameter to the other page, where you retrieve it, unencode it, and then load the serialized object.
Or you can just use the session. -
How to pass record Group from Forms with DATA_PARAMETER to Reports Server
How to pass record Group from Forms with DATA_PARAMETER to Reports Server using RUN_REPORT_OBJECT?
When we use products on run time we are using data_parameter for passing record Groups to reports via run_product but now we have to use application server and reports server for same reports.
We met with <FRM-41214 Unable to run reports> for passing DATA_PARAMETER to reports server when used RUN_REPORTS_OBJECT.
How can we pass record Group from Forms with DATA_PARAMETER to Reports Server using RUN_REPORT_OBJECT?
Thanks,
ArifHi Mandeep,
Could you please tell me how can i pass data parameter from forms to report through run_product. -
Passing values to form bean string array from dynamic added textboxes
Hi,
I am unable to pass values to form bean string array from a jsp in which I have incorporated dynamically adding of textboxes in javascript.
I have given add/delete row option in the jsp. If there is single row, this is working fine. But after adding a row, I am not able to either do any validations on added textboxes or pass the values to the String array form bean variable.
code snippet:
var cell6 = row.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text";
element5.className = "formtext1";
element5.size = "5";
element5.value = "00.00";
element5.name= "qty"; // this is a string array of the form bean.
element5.onchange=function() {checkNumeric(this);};
cell6.appendChild(element5);
<html:text styleClass="formtext1" property="qty" value="" size="5" styleId="qty" onchange="checkNumeric(this)"/></td>
form bean declaration
private String[] qty; Please help.
Edited by: j2eefresher on Jan 12, 2010 11:23 PMShivanand,
There's no need to post that much code when you could create a very short test case that demonstrates only the problem you are having.
You're using &NAME. notation on something that isn't a page or application item. You can't reference PL/SQL variables that way (or any other way) outside the PL/SQL scope. For your situation, you could create a page item named P55_DOCID and assign it a value in the PL/SQL process (:P55_DOCID := DOCID;), then reference &P55_DOCID. in HTML areas like the success message.
Scott -
Passing an array from one method to another
I am passing an array from my "load" method and passing it to be displayed in my "display" method in an applet .
I made the array a class variable (to be able to pass it to the "display" method).
The applet runs, but nothing seems to be in the array.The screen says applet started, but nothing else. There does not seem to be any CPU activity.
Trying to debug this, I have tried to paint the screen during the array build. I never figured out how to do this. So I made this a non applet class, put it in debug, and the array seems to load okay.
Any help is appreciated.
This is the applet code:
import java.applet.Applet;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.net.*;
public class urla extends java.applet.Applet
int par1;
int i = 1;
int j = 20;
int m = 0;
int k = 0;
String arr[] = new String[1000];
String inputLine;
public void load() throws Exception
try
URL mysite = new URL("http://www.xxxxxxxxxxxxxx.html");
URLConnection ms = mysite.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
ms.getInputStream()));
while ((inputLine = in.readLine()) != null)
arr[m] = inputLine;
m++;
in.close();
catch (MalformedURLException e)
k++;
public void display(Graphics screen)
screen.drawString("THE FOLLOWING HAVE ADDED THEIR BIOS:",5 ,5);
for (int i = 0; i < 20; i++);
j = j + 20;
screen.drawString("output - "
+ arr, 5, j);
repaint() ;
}String arr[] = new String[1000];is this typing mistake????? because if u did it in
program as well i don think it will work.. the tag is
innnside array lenght... hope iam saying this right!!no, he had the bold form tags (b and /b inside square brackets) in his previous non-code tagged post. He carried it over to this post and they caused an error. I highly doubt that they were in his actual program. Just delete them.
Message was edited by:
petes1234
Maybe you are looking for
-
the call/text sounds don't work. Neither do sounds coming from the games I play(clash of clan) or other apps I use such as snapchat/vine. the sounds only When I play music/videos
-
BEx Analyzer not working in SAP GUI 7.10
Dear All, BEx Analyzer 7.0 is not working on SAP GUI 7.10. Following are the details: OS: Windows XP SP2 Installed the following softwares (in the sequential order): 1. Microsoft .Net Framework 2.0 SP1 2. MS Office 2003 (without any service packs) 3.
-
Getting error while expanding SQL Server 2012 agent.
Hi All, Server Version Details: Microsoft SQL Server 2012 (SP1) - 11.0.3000.0 (X64) Oct 19 2012 13:38:57 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) We are using SQL S
-
HP 8500 Wireless printer will not install - HELP!
I am using a new i7 MacBook Pro with boot camp running Windows 7 Professional 64bit with 8mb RAM. When trying to install my new HP8500 Wireless printer I get this error message: "Problem with the driver for Intel 5 Series/3400 series chipset family U
-
10.6.8 MBP 2008/9 not a complainer at all unless it is serious and can be triplicated in all applications the cursor moves and type lands in previous lines type will erratically move to other lines type will disappear endless and anything goes here