Calling Stored Proc returning count of records(int value) using hibernate
Hi ,
I am a newbie in hibernate. i have a store proc that returns the count of amtchin records, i want to call the store proc using hibernat.Can anyone help me out in this.
Thanks ,
Dilip
http://asktom.oracle.com/pls/ask/f?p=4950:8:6003223320663969737::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:246014735810,
Similar Messages
-
SQL Exception: Invalid column index while calling stored proc from CO.java
Hello all,
I am getting a "SQL Exception: Invalid column index" error while calling stored proc from CO.java
# I am trying to call this proc from controller instead of AM
# PL/SQL Proc has 4 IN params and 1 Out param.
Code I am using is pasted below
==============================================
OAApplicationModule am = (OAApplicationModule)oapagecontext.getApplicationModule(oawebbean);
OADBTransaction txn = (OADBTransaction)am.getOADBTransaction();
OracleCallableStatement cs = null;
cs = (OracleCallableStatement)txn.createCallableStatement("begin MY_PACKAGE.SEND_EMAIL_ON_PASSWORD_CHANGE(:1, :2, :3, :4, :5); end;", 1);
try
cs.registerOutParameter(5, Types.VARCHAR, 0, 2000);
cs.setString(1, "[email protected]");
cs.setString(2, s10);
//Debug
System.out.println(s10);
cs.setString (3, "p_subject " );
cs.setString (4, "clob_html_message - WPTEST" );
outParamValue = cs.getString(1);
cs.executeQuery();
txn.commit();
catch(SQLException ex)
throw new OAException("SQL Exception: "+ex.getMessage());
=========================================
Can you help please.
Thanks,
VinodYou may refer below URL
http://oracleanil.blogspot.com/2009/04/itemqueryvoxml.html
Thanks
AJ -
Calling stored proc from java to return ref cursor
Hi All,
We have a requirement to display all the records from a table on a JAVA screen. Due to some constraints, we have to write the query in the stored proc. We are trying to return a result set from the stored proc to the java code by using a ref cursor. Please refer to the code below.
Following is the PL/SQL proc ?
procedure sp_user_course2(v1 OUT ref_cursor, persid in varchar2) as
begin
open v1 for
SELECT lrn_exp_id, crs_name FROM emp_crs
WHERE personid = persid;
end;
Here ref_cursor is of TYPE REF CURSOR declared in the package specification.
The java code is ?
Callable stmt = conn.prepareCall("call sp_user_course2(?,?)");
stmt.registerOutParameter(1,OracleTypes.CURSOR);
stmt.setString(2,emplId);
stmt.execute();
OracleCallableStatement tstmt = (OracleCallableStatement) stmt;
ResultSet rs = tstmt.getCursor (1);
When I run the program, I get the following error (at stmt.execute()):
[Oracle][ODBC][Ora]ORA-06553: PLS-306: wrong number or types of arguments in call to 'SP_USER_COURSE2' 6553
Can anyone tell me what could be the problem with this code? I have read somewhere that REF CURSOR feature is available from Oracle 9i onwards. If so, then, is there any workaround for mapping REF CURSOR to Resultsets in Oracle 8i?These may help
http://www.google.co.uk/search?q=jdbc+OracleTypes.CURSOR+tutorial -
Hello!
I have developed a Java application which calls stored procedures, some of which return a ResultSet (always one).
I need to support more DBMS vendors, so I used the standard JDBC syntax to call the stored procedures ({call storedProcedure(?,?)}).
I developed the code using MySQL, but succeded to call SQL Server 2000 stored procedures changing only the driver (that's the purpose of JDBC, right?).
Now I need to support the Oracle DBMS, but I can't find a way to create a stored procedure which returns a result set and allows me not to change the already stable Java code.
How could I achieve this result? Should I use some other Oracle object, say a function?
By the way, I searched the Internet, but only found solutions which would've made me change code. This is definitely not portable
Thank you very much for your help!
PS: Some of the stored procedures return both a ResultSet AND OUT parameters.Hello and thanks for your reply, jwenting.
However, keeping useless "philosophy" out of this thread, please just let me clarify that I obviously didn't want portability of stored procedures, I just wanted a standard JDBC to interface with them. I haven't had problems in the past with stored procedures and other DBMSs, I'm having them just now with the Oracle JDBC driver. Since JDBC is meant to be portable, I hoped there was a portable way of calling Oracle stored procedures (or whatever else in Oracle takes inputs and returns output and a ResultSet...). Unfortunately, there doesn't seem to be any, unless I use a commercial driver from DataDirect. I find this a heavy limitation of the Oracle JDBC driver, but, alas, here it is... I'll have to refactor my stable code...
Thanks again... -
Calling stored proc from java using ref cursor
Hi All,
We have a requirement to display all the records from a table on a JAVA screen. Due to some constraints, we have to write the query in the stored proc. We are trying to return a result set from the stored proc to the java code by using a ref cursor. Please refer to the code below.
Following is the PL/SQL proc �
procedure sp_user_course2(v1 OUT ref_cursor, persid in varchar2) as
begin
open v1 for
SELECT lrn_exp_id, crs_name FROM emp_crs
WHERE personid = persid;
end;
Here ref_cursor is of TYPE REF CURSOR declared in the package specification.
The java code is �
Callable stmt = conn.prepareCall("call sp_user_course2(?,?)");
stmt.registerOutParameter(1,OracleTypes.CURSOR);
stmt.setString(2,emplId);
stmt.execute();
OracleCallableStatement tstmt = (OracleCallableStatement) stmt;
ResultSet rs = tstmt.getCursor (1);
When I run the program, I get the following error (at stmt.execute()):
[Oracle][ODBC][Ora]ORA-06553: PLS-306: wrong number or types of arguments in call to 'SP_USER_COURSE2' 6553
Can anyone tell me what could be the problem with this code? I have read somewhere that REF CURSOR feature is available from Oracle 9i onwards. If so, then, is there any workaround for mapping REF CURSOR to Resultsets in Oracle 8i?These may help
http://www.google.co.uk/search?q=jdbc+OracleTypes.CURSOR+tutorial -
Hi All,
I have a simple stored proc in SQL server 2000
CREATE PROCEDURE dbo.sp_myProc
AS
SELECT CategoryID,CategoryName from Categories
GO
My java code is
CallableStatement cs = connection.prepareCall("{? = call sp_myProc}");
cs.registerOutParameter(1, Types.VARCHAR);
boolean result = cs.execute();
System.out.println("Result : "+result);
ResultSet rs = (ResultSet)cs.getResultSet();
while(rs.next())
System.out.println(rs.getString("CategoryID"));
When I execute this, the stored procedure gets executed succesfully i.e, the Result is true.
But the resultset object : rs is Null. It returns a null pointer exception at rs.next();
The table has values & this returns proper values in SQL analyzer.
I use Microsoft JDBC drivers for SQL server.
Is there anything I am doing wrong, all examples i saw refered to the same thing. I am struck with this any help would be appreciated.
Thanks in advance,
SudhindraSorry - small mistake here.
The number of ? marks in the () brackets = the number of parameters in the procedure.
Thus with your procedure nothing gets returned.
With an Oracle Db you will declare the proc as follows:
PROCEDURE abcd (par1 IN OUT VARCHAR2, par2 IN OUT VARCHAR2)
IS
BEGIN
SELECT abc, def INTO par1, par2 FROM xyz;
END;
Thus you will register two in String parameters AND two out String parameters.
If you require more than one record to be returned the you need to have a look at some collection type to be returned other than VARCHAR2.
Andre -
Calling stored proc via services
I would be grateful if you could help me in resolving a technical issue in CMS(stellent).
We have a requirement that we need to call a stored procedure through services .The stored proc takes an input argument and returns a result set and has a defination that starts like
create or replace
PACKAGE BODY GETPROJECTPCKG IS
PROCEDURE PROC_RPU (rpu_list_count IN number, temp_project_cursor OUT project_ref_cursor) IS.
I've defined a service call like
<tr>
<td>GET_RPU_INFO</td>
<td>DocService
33
RECENTPROJECTUPDATE
null
null<br>
null</td>
<td>5:QgetRpuNames:temp_project_cursor::null</td>
</tr>
And below is how I've called the procedure
<tr>
<td>QgetRpuNames</td>
<td>{call GETPROJECTPCKG.PROC_RPU(?)}</td>
<td>rpu_list_count int</td>
</tr>
i tried calling procedure as below also ..
<tr>
<td>QgetRpuNames</td>
<td>{call GETPROJECTPCKG.PROC_RPU(?,?)}</td>
<td>rpu_list_count int
temp_project_cursor out:resultset</td>
</tr>
As per my understanding the temp_project_cursor which is the resultset that would be returned from procedure should be available on the template specified.
But while executing the service I am getting an error :
Unable to create result set for query 'QgetRpuNames({call GETPROJECTPCKG.PROC_RPU(10)})'. ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PROC_RPU'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored)
Can you please assist.Hey
if this is still an issue please refert "Call Stored Procedure from Oracle Fusion ECM (Stellent) " at http://www.corecontentonly.com/index.php/downloads/. Jason has shared a component that you can make use of.
cheers,
sapan -
Error in calling Stored procedure returns REFCURSOR
Hi,
I've written a oracle stored procedure returning REFCURSOR. say,extractorderdespatchconfirmsp('','','','','','H1','ACG','','','','',:rc).
Following statement throwing error.
CallableStatement cs = con.PrepareCall("{extractorderdespatchconfirmsp('','','','','','H1','ACG','','','','',:rc)}");
rs = cs.executeQuery();
Could you rectify this problem and give me the currect code.
riyazYour naming convention leaves a little to be desired.
String command = "{CALL extractorderdespatchconfirmsp(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
CallableStatement cstmt = conn.prepareCall(command);
//set the variables here ie, dates need to be a timestamp format. use set timestamp.
cstmt.setInt(1, 2);
cstmt.setString(2, "a string");
cstmt.setInt(3, 0);
//for return values
cstmt.registerOutParameter(3, Types.INTEGER);
cstmt.registerOutParameter(2, Types.INTEGER);
cstmt.execute();
int status = cstmt.getInt(3);
int status2 = cstmt.getInt(2);
cstmt.close();
It took me awhile too to get JDBC to call these right. -
Problem calling Stored Procedure returning SETOF UDT (Using Spring)
I am using Spring's StoredProcedure class to call a stored procedure from a PostgreSql database. It returns a set of user defined data types. I'm having a problem in parsing the results returned.
The user defined data type :
CREATE TYPE process_states AS (
process_name text,
process_type text
The stored procedure returns a SET of "process_state" :
CREATE FUNTION inquire_process_state (.....)
RETURNS SETOF process_state AS '
SELECT ....
I hava a Java class extending the Spring StoredProcedure classs.
public MyProcStats extends StoredProcedure {
private class ProcStateCallBackHandler implements RowCallBackHandler {
public void processRow(ResultSet rs) throws SQLException {
System.out.println(rs.getString(1));
public MyProcStats (DataSource ds) {
super(ds, "inquire_process_state");
super.setFunction(true);
declareParameter(new SqlOutparameter("rs", Types.OTHER, new ProcStateCallBackHandler());
declareParameter(new SqlParameter("family_name", Types.VARCHAR) ;
While testing this class, I get an errormessage
"java.sql.SQLException:ERROR: cannot display a value of type record"
I would appreciate if anyone can point out my mistakes. I tried declaring
new SqlOutParameter("rs", Types.OTHER, "process_state"), but that didn't help.As the related posts suggest, you will need to use direct JDBC code for this.
Also I'm not sure JDBC supports the RECORD type, so you may need to wrap your stored functions with ones that either flatten the record out, or take OBJECT types. -
Calling stored proc through JDBC
Hello all,
What I am doing is calling a stored proceedure in this manner...
CallableStatement stmt = dbB.getConn().prepareCall ("call LDPKG.LDGetData(?, ?)"); //dbB is a conn Class I made, it works fine and getConn obviously jsut returns teh Connection object... Those work fine disreguard them.
stmt.registerOutParameter(1, <IDONTKNOW>); //I dont know the return type
stmt.registerOutParameter(2, <IDONTKNOW>); //I dont know the return type
stmt.execute();I am unsure of what to put for the return type... The DB has these TYPES created as teh OUT for the stored Proc ...
TYPE t_returnId is table of LDDATA.UserId%TYPE index by BINARY_INTEGER
TYPE t_returnName is table of LDDATA.UserName%TYPE index by BINARY_INTEGER
I dont know how to translate that return type to Java... Any ideas???
Thanks!If you want the whole thing it is like this... I just didnt see the point in being redundant with the output types. Now that Date is an issue I brought it up. didnt think i needed to before.. sorry.
OracleCallableStatement stmt = (OracleCallableStatement)dbB.getConn().prepareCall ("begin LDPKG.LDGetData(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); end;");
stmt.registerIndexTableOutParameter(1,500, OracleTypes.NUMBER, 0);
stmt.registerIndexTableOutParameter(2,500, OracleTypes.DATE, 0);
stmt.registerIndexTableOutParameter(3,500, OracleTypes.VARCHAR, 0);
stmt.registerIndexTableOutParameter(4,500, OracleTypes.VARCHAR, 0);
stmt.registerIndexTableOutParameter(5,500, OracleTypes.VARCHAR, 0);
stmt.registerIndexTableOutParameter(6,500, OracleTypes.VARCHAR, 0);
stmt.registerIndexTableOutParameter(7,500, OracleTypes.VARCHAR, 0);
stmt.registerIndexTableOutParameter(8,500, OracleTypes.VARCHAR, 0);
stmt.registerIndexTableOutParameter(9,500, OracleTypes.NUMBER, 0);
stmt.registerIndexTableOutParameter(10,500, OracleTypes.VARCHAR, 0);
stmt.registerIndexTableOutParameter(11,500, OracleTypes.VARCHAR, 0);
stmt.registerIndexTableOutParameter(12,500, OracleTypes.VARCHAR, 0);
stmt.registerIndexTableOutParameter(13,500, OracleTypes.VARCHAR, 0);
stmt.registerIndexTableOutParameter(14,500, OracleTypes.VARCHAR, 0);
stmt.execute();I'm still looking through Google but not finding much about this :(. -
Use 'default' keyword in call string while calling stored proc?
I am calling following sql server stored procedure from java code using my jdbc driver for sql server: CREATE PROCEDURE test_findTbInfo (
@paramIn_Str varchar(10),
@paramOut_Int int OUT,
@paramIn_Int int = 20
AS
begin
set @paramOut_Int = @paramIn_Int * 100
end
If I make a call like this:
CallableStatement cs = conn.prepareCall(" { call test_findTbInfo(? , , ? ) }");
cs.setString(1, "test_tab");
cs.setInt(2, 4);
cs.execute();
It works without any error. But this is not a right behavior. !! The second parameter as you see is passed like an optional parameter. But in stored proc it is NOT an optional param and so if the value not passed it should fail...
Now if I change the code to
CallableStatement cs = conn.prepareCall(" { call test_findTbInfo(? , default, ? ) }");
it works correctly. Gives error that "Procedure 'test_findTbInfo' expects parameter '@paramOut_Int', which was not supplied." which is correct.
So is it a normal practice to use 'default' keyword while calling sql server stored procedures having optional parameters in jdbc ????
Anyone knows ??? As far as I know "call test_findTbInfo(? , , ? )" works fine except in some cases and also it forces users to put all optional parameters at the end of parameter list in stored proc.
Please let me know whether I should go with 'default' throuout for sql server stored proc while calling using my jdbc driver.
Amit{?= call <procedure-name>[<arg1>,<arg2>, ...]}The question mark in the above is the result parameter
that must be registered.
That is not the same as an OUT argument.Yes that is true. The result value and OUT parameters are different but they both MUST be registered as per jdbc API
"The type of all OUT parameters must be registered prior to executing the stored procedure; their values are retrieved after execution via the get methods provided here."
Anyway, my original question still stays as it was. If there are some optional IN parameters in stored procedure
e.g.
PROCEDURE test_findTbInfo (
@paramIn_Int int = 20,
@paramOut_Int int OUT
how do you call this?
CallableStatement cs = conn.prepareCall(" { call test_findTbInfo( , ? ) }");
cs.registerOutParameter(1, Types.INTEGER);
cs.execute();
or
CallableStatement cs = conn.prepareCall(" { call test_findTbInfo(default, ? ) }");
Also note that I am intending to use ONLY sql server driver for this.
The first as well second seem to work. Except that second way is seems reliable. I just wanted a second opinion on that...
Amit -
Call stored proc from inside sp
I am trying to call a stored proc from inside a stored proc and the stored proc needs to return a ref_cursor. I am trying to loop over the returned ref_cursor, but my problem is that when I compile the sp it says the ref_cursor is not a procedure or is undefined. Can anyone please tell me why I am getting this error? Refer to the code below!
create or replace
PROCEDURE TCS_GetPartReferenceData
contracts IN VARCHAR2
, showInWork IN INTEGER
, userClock IN VARCHAR2
, intMaxResults IN INTEGER
, ret_cursor OUT SYS_REFCURSOR
) AS
p_cursor SYS_REFCURSOR;
BEGIN
TCS_GETDRNSFORCONTRACTS(contracts
, showinwork
, userClock
, intmaxresults
, p_cursor);
for r in p_cursor loop
dbms_output.put_line(r.puid);
end loop;
END TCS_GetPartReferenceData;Probably you want sth. like
CREATE OR REPLACE PROCEDURE tcs_getpartreferencedata (contracts IN VARCHAR2,
showinwork IN INTEGER,
userclock IN VARCHAR2,
intmaxresults IN INTEGER,
ret_cursor OUT sys_refcursor)
AS
BEGIN
tcs_getdrnsforcontracts (contracts,
showinwork,
userclock,
intmaxresults,
ret_cursor);
END tcs_getpartreferencedata;
var cur refcursor
exec tcs_getpartreferencedata(contracts_value,showinwork_value,userclock_value,intmaxresults_value, :cur)
print curfill in appropriate values for the parameters _value .... -
Hello!
We use TT as CacheConnect to Oracle Database 10g. Can we call Oracle Database 10g stored proc from our C++ application? Than passthrough level we must to use if we can perform this call?
Thank you!You can call Stored procedures using PassThrough=3 provided that the procedure does not return any values.
Note that the procedure will execute in Oracle against Oracle data not against TimesTen data.
Chris -
JDBC-Adapter-Receiver Calling Stored Procedure with Input-Typ Record
Hallo,
I´ m trying calling a stored-procedure with two input-parameter; one of typ record (oracle) and one of type tabel of records. Is this possible (I think there are only types like string, integer etc. possible)? When not is there another possibility to work with that type?
Thanks in advance,
FrankHi Frank,
I think stored procedures will not take Array of Records as a Input. If you want to make a loop funtionality etc then JDBC adapter will work accordingly. You need to just call the stored procedure from the JDBC adapter. It will work for the array of records(multiple occurences).
Receiver JDBC Procedures.
/people/siva.maranani/blog/2005/05/21/jdbc-stored-procedures
Alternative option is you can make use of Java Proxy and from there you can call stored procedure ..I think it is possible.. not tried.
Hope this helps
Regards,
Moorthy -
Calling stored proc (with 2 IN and 3 OUT) - from SQL Plus
This is the signature of my stored proc:
CREATE OR REPLACE PROCEDURE myschema.myproc
p_usr_name IN VARCHAR2,
p_send_tmstmp IN DATE,
p_ret_value OUT NUMBER,
p_err_code OUT VARCHAR2
)If I need to call it from sql plus, how do I need to pass the arg?
This is what I am doing
execute myschema.myproc('abc123','02-MAY-2008');
What is wrong here? If someone could help. Thx!Try something like this
var usr_name varchar2(30)
var send_tmstmp varchar2(11)
var ret_value number
var err_code varchar2(10)
begin
:usr_name := 'abc123';
:usr_name := '02-MAY-2008';
myschema.myproc ( p_usr_name => :usr_name,
p_send_tmstmp => TO_DATE( :usr_name, 'DD-MON-YYYY' ),
p_ret_value => :ret_value,
p_err_code => :err_code);
end;
print ret_value;
print err_code;
Maybe you are looking for
-
Mail App Not Opening After Upgrading to Yosemite
I upgraded to Yosemite this morning from Mountain Lion. Everything seemed to go well until I clicked Mail for the first time. The migration process started, but the app never opened and will not open. I immediately get a crash dialog and that's it. I
-
Can I use Hot Corners to make the display sleep immediately?
I have Hot Corners set up so that the screen-saver kicks in as soon as I move the mouse to the top-right corner. However, I'd really like to be able to make the display sleep immediately, rather than show the screen-saver first... can I do that? Ther
-
Conneced to wireless router but no internet access via wireless
I don't recall the physical connections being directly attached to the router. The router in question is a Linksys WRT54G/GL/GS. My initial thought was since we rolled out Voip fairly recently one of our phones might have ganked the IP address, but
-
Restricting the Prompt Values based on Fact table data
Hi, We need dashboard prompts in OBIEE reports that will fetch data from dimension tables. Our all dimensions are conformed dimension having joined with multiple fact tables. Because prompts are showing data from dimension table, it is showing all di
-
This is rediculass is there any managers or emolyes wgo care
K this is really ridiculous. Does Verizon not care about there customers satisfaction! I've went through 3 phones of the same. This last phone I just activated and the lock button started intermediary working. And I call them they said they would upg