Pass java HASHMAP to oralce procedure
Hi,
I have Java HashMap(<key, value). Can i pass it to oracle procedure?
I am using java 1.4 and oracle 10g.
any help
Hi,
Some information, From the point of the view that the need is to pass an object from java to PLSQL or vice versa (Not HashMap, but data which can be manipulated in PLSQL)
What you need to do/investigate is ..
1. Load your java files to database (using loadjava integrated in JDev better, else seperately)
2. Create PLSQL procedure for the java method using JDev)
3. Define PLSQL object which you want to use as counter part of the java object. (Its reverse, first create plsql object)
4. In jdeveloper connection navigator,use generte java to generate corresponding java object class.
The above information is to fascilitate information exchange between java and PLSQL in terms of Objects. Based on one of projects I had done.
If abouvGive a little try and probably you may be able to do reverse (first define Java OBject (you have HashMap here) and then the PLSQL Object.)
Most of the things are automated in JDeveloper. Just explore it.
Abdul Wahid
Similar Messages
-
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. -
Passing data from Oracle stored procedures to Java
We're going to write a new web interface for a big system based on Oracle database. All business rules are already coded in PL/SQL stored procedures and we'd like to reuse as much code as possible. We'll write some new stored procedures that will combine the existing business rules and return the final result dataset.
We want to do this on the database level to avoid java-db round trips. The interface layer will be written in Java (we'd like to use GWT), so we need a way of passing data from Oracle stored procedures to Java service side. The data can be e.g. a set of properties of a specific item or a list of items fulfilling certain criteria. Would anyone recommend a preferable way of doing this?
We're considering one of the 2 following scenarios:
passing objects and lists of objects (DB object types defined on the schema level)
passing a sys_refcursor
We verified that both approaches are "doable", the question is more about design decision, best practice, possible maintenance problems, flexibility, etc.
I'd appreciate any hints.user1754151 wrote:
We're going to write a new web interface for a big system based on Oracle database. All business rules are already coded in PL/SQL stored procedures and we'd like to reuse as much code as possible. We'll write some new stored procedures that will combine the existing business rules and return the final result dataset.
We want to do this on the database level to avoid java-db round trips. The interface layer will be written in Java (we'd like to use GWT), so we need a way of passing data from Oracle stored procedures to Java service side. The data can be e.g. a set of properties of a specific item or a list of items fulfilling certain criteria. Would anyone recommend a preferable way of doing this?
We're considering one of the 2 following scenarios:
passing objects and lists of objects (DB object types defined on the schema level)
passing a sys_refcursor
We verified that both approaches are "doable", the question is more about design decision, best practice, possible maintenance problems, flexibility, etc.
I'd appreciate any hints.If logic is already written in DB, and the only concern is of passing the result to java service side, and also from point of maintenance problem and flexibility i would suggest to use the sys_refcursor.
The reason if Down the line any thing changes then you only need to change the arguments of sys_refcursor in DB and as well as java side, and it is much easier and less efforts compare to using and changes required for Types and Objects on DB and java side.
The design and best practise keeps changing based on our requirement and exisiting design. But by looking at your current senario and design, i personally suggest to go with sys_refcursor. -
Passing an array as parameter from java (java controls) to stored procedure
Hi,
I'm using java controls (BEA Weblogic Workshop 8.1) to call a stored procedure and send an array as a parameter to the stored procedure from java. The following code below throws an exception "Fail to convert to internal representation".
Java code
import com.bea.control.DatabaseControl.SQLParameter;
// Here i create the java array
int[] javaArray={12,13,14};
//The code below is used to create the oracle sql array for the procedure
SQLParameter[] params = new SQLParameter[1];
Object obj0=javaArray;
params[0] = new SQLParameter(obj0, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN);
// the code below calls the testFunc method in OJDBCtrl.jcx file
String succ= dbControl.testFunc(params);
OJDBCtrl.jcx
* @jc:sql statement="call CMNT_TST_PROC(?))"
String testFunc(SQLParameter[] param);
The stored procedure used:
TYPE SL_tab IS TABLE OF number INDEX BY PLS_INTEGER;
Procedure cmnt_tst_proc (cmnt_tst sl_tab);
Procedure cmnt_tst_proc (cmnt_tst sl_tab) is
BEGIN
dbms_output.put_line('Hello');
END;
I am getting the following exception
Failure=java.sql.SQLException: Fail to convert to internal representation: [I@438af4 [ServiceException]>
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
at oracle.jdbc.driver.DatabaseError.check_error(DatabaseError.java:861)
at oracle.sql.ARRAY.toARRAY(ARRAY.java:210)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7768)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7449)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7837)
at oracle.jdbc.driver.OracleCallableStatement.setObject(OracleCallableStatement.java:4587)
at weblogic.jdbc.wrapper.PreparedStatement.setObject(PreparedStatement.java:244)
at com.bea.wlw.runtime.core.control.DatabaseControlImpl._setParameter(DatabaseControlImpl.jcs:1886)
at com.bea.wlw.runtime.core.control.DatabaseControlImpl.getStatement_v2(DatabaseControlImpl.jcs:1732)
at com.bea.wlw.runtime.core.control.DatabaseControlImpl.invoke(DatabaseControlImpl.jcs:2591)
at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:377)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:433)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:406)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:249)
at com.bea.wlw.runtime.jcs.container.JcsContainer.invoke(JcsContainer.java:85)
at com.bea.wlw.runtime.core.bean.BaseContainerBean.invokeBase(BaseContainerBean.java:224)
at com.bea.wlw.runtime.core.bean.SLSBContainerBean.invoke(SLSBContainerBean.java:109)
at com.bea.wlwgen.StatelessContainer_ly05hg_ELOImpl.invoke(StatelessContainer_ly05hg_ELOImpl.java:153)
Can you please let me know, what i'm doing wrong and how i can pass an array to a procedure/function using java controls.
Any help will be highly appreciated.
Edited by: user12671762 on Feb 24, 2010 5:03 AM
Edited by: user9211663 on Feb 24, 2010 9:04 PMThanks Michael.
Here's the final code that i used, this might be helpful for those who face this problem
Java Code
// Following code gets the connection object
InitialContext ctx = new InitialContext();
dataSource = (DataSource)ctx.lookup("<DataSourceName>");
conn=dataSource.getConnection();
// Following code is used to create the array type from java
String query="CREATE OR REPLACE TYPE STR_ARRAY AS VARRAY(3) OF NUMBER";
dbControl.runTypeQuery(query);
// Following code is used to obtain the oracle sql array as SQLParameter
ArrayDescriptor desc = ArrayDescriptor.createDescriptor("<schemaName>.STR_ARRAY", conn);
Object[] elements = new Object[3];
elements[0] = new Integer(12);
elements[1] = new Integer(13);
elements[2] = new Integer(14);
oracle.sql.ARRAY newArray = new oracle.sql.ARRAY( desc, conn, elements);
SQLParameter[] params = new SQLParameter[1];
params[0] = new SQLParameter(newArray, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN);
String succ= dbControl.testFunc(params); -
How can i pass the parameter for strored procedure from java
dear all,
I am very new for stored procedure
1. I want to write the strored procedure for insert.
2. How can i pass the parameter for that procedure from java.
if any material available in internet create procedure and call procedure from java , and passing parameter to procedure from javaHi Ram,
To call the callable statement use the below sample.
stmt = conn.prepareCall("{call <procedure name>(?,?)}");
stmt.setString(1,value);//Input parameter
stmt.registerOutParameter(2,Types.BIGINT);//Output parameter
stmt.execute();
seq = (int)stmt.getLong(2);//Getting the result from the procedure. -
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 -
The best way pass a goemetry to a procedure
I need to pass a geometry to a stored procedure. I first thought of using the mdo.sys_geometry types but the java client cannot pass in this type of object. I then thought of using pl/sql tables to send in the sdo_element_info array and the sdo_ordinate_array info. I had a concern that the shape I passed in would surpass the sql buffer for the pl/sql ( if there is a buffer length as there is in sqlplus ). I also thought of using a long datatype to pass in an infinite string that I can parse and and create the goemetry in the stored procedure. Anybody have any thoughts as to the best way to pass a geometry into a procedure?
They will be able to download everything that was bought with their Apple ID. If they all shared an ID then they switched to their own ID they won't be able to use any apps or music bought with another Apple ID. As I explained in my previous response. There is only one way to share apps and content across multiple Apple ID's and that is home share. So, NO there isn't a "Smooth" way to do it.
-
Pass xmltype to oracle stored procedure
I need to pass an xmltype from java to an oracle stored procedure. Does anybody have any sample code to do this? I am using jdeveloper 10.1.2
Thanks
MMOracle provides several ways of passing objects to and from java to Oracle Stored Procedure.
One way is to directly create oracle.sql.STRUCT object and pass array of values to this object. Another way is to implement java.sql.SQLData or oracle.sql.ORAData interfaces in your class and pass this class to setObject function.
It is all well described in manual in chapter "Working with Oracle Object Types", there is also a lot of examples in this chapter and on the web.
http://download-uk.oracle.com/docs/cd/B19306_01/java.102/b14355/oraoot.htm - Working with Oracle Object Types
Some of the examples:
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/ObjectOracleSample/Readme.html
http://javaalmanac.com/egs/java.sql/InsertObjectOraclePreparedStatement.html -
Passing multidimensional array to plsql procedure
hi ,
is there any way to pass a two dimensional array of different data types to plsql procedure as a parameter?
In other words, is it possible to pass a set or records or a datatable as a single parameter to plsql procedure?
Because I am using a dataset selected with odp.net in my client and I am modifying the data in different datatables contained in the dataset.At the moment, the modified datatables are saved by seperating each column as a sepearate array and passing each column array as a seperate parameter to a stored procedure. But, I would like to change it in a way to pass each datatable as a single parameter to the stored procedure.
I would appreciate any solution/suggestion/hint in regard to this problem
thanks in advance,
Prabhakar.If your Java array is of a base type (String, int, etc.) and you are using the OCI driver, you can use OracleCallableStatement.setPlSqlTable(). (I'm doing this from memory so the method name may be slightly different.)
The method takes a Java array and converts it to a PL/SQL table before passing it to the stored procedure. -
Passing parameters to pl/sql procedure called in portal
Hi all,
I am trying to use a javascript window.open function to create a small popup window that is populated by a pl/sql procedure from inside portal.
I am trying to pass it a parameter to refine a SQL query running in that procedure, unfortunately I'm not sure of the syntax. The url that I'm trying to open in the new window looks like this:
http://my.server.com:7777/portal/pls/portal/myschema.mypackage.myprocedure
If I just run this, it works fine and the popup window opens correctly and displays all results. If I try to pass a parameter, it errors out with a 404 Page Not Found.
The parameter itself comes from a text field that the user can enter a value into. I am able to get the value of that text field and append it to the url I'm generating, but I can't find the proper syntax.
I've tried numerous syntax variants, but none of them seem to work. The procedure does have the parameter defined in both the spec and body and properly handles it. Can anyone point me in the right direction?
Thanks,
-Mike MarkiwYou said you have a text field where a user enters a value, so I am assuming that you have form...
you can try following
<form action="/pls/portal/myschema.mypackage.myprocedure" method="post">
your text field "inVar"
your submit button
</form>
I am sure your myprocedure has inVar as an input...
If you just want to pass a value to a procedure you can always do following:
http://my.server.com:7777/portal/pls/portal/myschema.mypackage.myprocedure?inVar=the value -
How to pass parameter from 1 stored procedure to another stored procedure inside crystal report
Hi
I have several stored procedure in my Crystal Report. I am wondering if it is possible for me to pass a parameter to one of the stored procedure and to use the result of that stored procedure E.g. CustomerCode. To another 2 stored procedure to generate the report dynamically?
I have 3 stored procedure
The 1st one is used to gather information and process the calculation
another 2 stored procedure is used for generate the graph and both of them required to take 2 parameters. The 1st stored procedure will require 1 parameter (E.G. Reference Code) and will return a set of information including the data that could be use on the other 2 stored procedures.
After I added these 2 stored procedure, it requires me to pass 3 parameters to the report. I would like to know if I could only pass the Reference Code for stored procedure 1 and use it to retrieve the information for the other 2 parameter?
Thanks in advance
ChiHi Chi
To pass parameter from 1 stored procedure to another stored procedure, you will have to create sub report. In your case you will have to create 2 sub reports for 2nd and 3rd stored procedure and link those sub reports with the main report using Reference Code field in order to pass the values.
After creating the report when you will refresh the report, it will ask 4 parameters, one parameter for main report, one for the first subreport and two for second subreport to fetch the data correctly.
Regards
Poonam Thorat. -
Can't we pass java.sql.Connection as parameter toDatum() method
I am in mid of java 1.3 to 1.4 migration, now I am getting the below error.can't we pass java.sql.Connection as a param to toDatum(), but I did the same before for another module and it worked fine, now I am getting the error.
any changes need to be done?
[b]toDatum(oracle.jdbc.driver.OracleConnection,java.lang.String) in oracle.jpub.runtime.MutableArray cannot be applied to (java.sql.Connection,java.lang.String)
return array.toDatum(c, SQL_NAME);
^
1 error
I changed to use
import oracle.sql.ORAData;
import oracle.sql.ORADataFactory;
instead of
import oracle.sql.CustomDatum;
import oracle.sql.CustomDatumFactory;In general, it's bad practice to be that "open" with regards to parameters to methods, especially when using remote invocations. However, if you really, really, really, really need to - and I doubt you do - you can use Serializable for the type of parameter. But that's still inelegant and, well, raises all sorts of issues, starting with your design...
-
Calling java class in oracle procedure
i have one simple java program that prints 'hi' . i want to call that java program from pl/sql procedure.how to do that.
This is one method I am demonstrating.
SQL> CREATE or REPLACE AND COMPILE JAVA SOURCE NAMED "HiWorld" AS
2 public class HiWorld {
3
4 public static void MyMessage(String msg) {
5 // TODO Auto-generated method stub
6 System.out.println(msg);
7 }
8
9 }
10 /
Java created.
SQL> CREATE or replace PROCEDURE hi_world (p_command IN VARCHAR2)
2 AS LANGUAGE JAVA
3 NAME 'HiWorld.MyMessage(java.lang.String)';
4 /
Procedure created.
SQL> BEGIN
2 DBMS_JAVA.SET_OUTPUT(1000000);
3 hi_world('Saubhik');
4 End;
5 /
PL/SQL procedure successfully completed.
SQL> set serverout on
SQL> /
Saubhik
Saubhik
PL/SQL procedure successfully completed.Another method is loading the class file with "loadjava" command. In that case first step "CREATE or REPLACE AND COMPILE JAVA SOURCE NAMED "HiWorld" AS" is not required. -
Passing table name to a procedure and then need to open a cursor ..
Hi All,
I have been out of touch in plsql for sometime and need to do something like :
passing table name to a procedure while calling(fp_table_old captures this value) and then need to open a cursor for this table in 'for i in (select * from fp_table_old )', one of the ways I tried is : for i in (execute immediate Lv_sql_query ) but its not working for me, please find the code below for reference, I know I am sounding stupid but I have been very out of touch, please help.
code :
create procedure p_table_compare(fp_table_old in varchar2, fp_table_new in varchar2)
as
Lv_sql_query varchar2(2000);
begin
Lv_sql_query := 'select * from '||fp_table_old;
for i in (Lv_sql_query)
loop
dbms_output.put_line(i.employee_id);
end loop;
end;
Regards
Rahulif I am doing something like this : for i in (execute immediate Lv_sql_query)
I am getting an error which is :
PLS-00103: Encountered the symbol "IMMEDIATE" when expecting one of the following:
. ( ) , * @ % & | = - + < / > at in is mod remainder not
range rem => .. <an exponent (**)> <> or != or ~= >=
My code:
create or replace procedure p_table_compare(fp_table_old in varchar2, fp_table_new in varchar2)
as
Lv_sql_query varchar2(2000);
begin
--dbms_output.put_line('Hello World');
Lv_sql_query := 'select * from '||fp_table_old;
for i in (execute immediate Lv_sql_query)
loop
dbms_output.put_line(i.employee_id);
end loop;
end;
Please help.
Regards
Rahul -
Can be passed Formula Column value to Procedure/Function?
Below cf_value is return after some calculation by using main query.
Can be directly passed formula column value to procedure without assinged to placeorder?
as below..
f_convert(:cf_value,new_value);
My Procedure is...
PROCEDURE f_convert( val1 in number,val2 in out number) IS
BEGIN
val2 := val1 * 100;
END;
If anyone knows pls reply me....Actually, if there is any other calculations there (In Proceudre)
Can I used is as below??
PROCEDURE f_convert( val1 in number,val2 in out number) IS
BEGIN
val2 := val1 * 100;
return (val2);
END;
----A procedure cannot return a value, the return clause in my previous post was part of the function for formula column.
Suppose you have a formula column say CF_2 then the function for it will be as:
function cf_2formula return number
is
val1 number;
val2 number;
begin
val2 := :cf_1 * 100; -- or val2 := val1 * 100 --parameters not allowed in formula column function
-- All the other code that you need inclusive of calling function, procedure as in any PL/SQL block can be placed
return (val2);
end;So any other calculation can be used in the formula column function
Maybe you are looking for
-
H:commandLink does not work on Safari
Hi, I'm using JBoss AS 4.2.2.GA with Seam 2.0.1.GA and all its standard libs. But this seems to be a JSF-RI issue which is used by JBoss 4.2.2.GA It seems as if <h:commandLink> don't work on Safari 3/Mac OS Leopard, which they did in earlier prjects
-
HP laserjet 1200 using windows7, cabled to the printer with a usb to parallel adapter
HP laserjet 1200 using windows7. My computer has USB ports, but no parallel port, so the computer is cabled to the printer with a usb to parallel adapter. Sometimes works fine, sometimes system states printer as ready, but will not print. Reboot hard
-
Which cable to use with macbook air
I need to do an extensive download. Right now I'm on our wirless network here at the house. I need to use a hardwire connection to our modem to decrease download time. Which cable do I need to connect to the modem? BTW we are on Comcast.
-
OSA - reading final appraisal (value text)
Hi, We are using Objective Setting & Appraisal and I need to display the final appraisal (text) on a form. I'm reading the final appraisal value from HTHAP_FINAL but I'm having problems reading the text. The appraisal ratings and descriptions exist i
-
Need repair of 17-35mm F 2.8 does not show up in repair support.
Lens has focus problem, does not go above 3m