Calling a stored procedure before row update without using triggers
I have got two tables Main Table(Table1) and History Table(Table2), whenever an update is done on Table1 i want to insert the old row before update to Table2, so that i have history available for that record.
My doubt is
how to refer to old value (values b4 update) in a stored procedure?
how to call a stored procedure b4 every row update(on the database side as we do with tiggers)?
I want to write a stored procedure where in i will insert the old row values ( value b4 update ) to Table2.
Any Help would be great....
sample code calling procedure before insert:
DriverManager.registerDriver(new someDriver);
Connection conn = DriverManager.getConnection(driver,uname,pword);
CallableStatement cs = conn.prepareCall("{call procedureName(?,?)}");
cs.setString(1,userName);
cs.registerOutParameter(2,Types.VARCHAR);
cs.execute();
success = cs.getString(2);
PreparedStatement pstmt = conn.prepareStatement("insert into sometable values(?,?)");
pstmt.setString(1,userName);
pstmt.setString(2,password);
pstmt.executeUpdate();
conn.commit();
cs.close();
conn.close();
Similar Messages
-
Call a Stored Procedure that returns a REFCURSOR using ODI Procedure
Hi,
I have a scenario wherein the stored procedure (TEST_PROC1) that returns a REFCURSOR. The second procedure(TEST_PROC2) will use the REFCURSOR as inpuut and insert it to a table.
Now, I need to execute the test procedures (TEST_PROC1 and TEST_PROC2) using the ODI Procedure but I always get error. However, I was able to execute the test procedures using sqlplus. Here is the command I used for sqlplus:
var rc refcursor
exec TEST_PROC1(:rc);
exec TEST_PROC2(:rc);
PL/SQL Stored Procedure:
-- TEST_PROC1 --
create or replace
PROCEDURE TEST_PROC1 (p_cursor IN OUT SYS_REFCURSOR)
AS
BEGIN
OPEN p_cursor FOR
SELECT *
FROM test_table1;
END;
-- TEST_PROC2 --
create or replace
procedure TEST_PROC2( rc in out sys_refcursor ) is
FETCH_LIMIT constant integer := 100;
type TFetchBuffer is table of test_table2%RowType;
buffer TFetchBuffer;
begin
loop
fetch rc bulk collect into buffer limit FETCH_LIMIT;
forall i in 1..buffer.Count
insert into test_table2(
c1, c2
) values(
buffer(i).c1, buffer(i).c2
exit when rc%NotFound;
end loop;
end;
Is there a way to call a PL/SQL Stored Procedure that returns a REFCURSOR using ODI Procedure?
Thanks,
CathyThanks for the reply actdi.
The procedure TEST_PROC1 is just a sample procedure. The requirement is that I need to call a stored procedure that returns a cursor using ODI and fetch the data and insert into a table, which in this case is test_table2.
I was able to execute a simple SQL procedure (without cursor) using ODI procedure. But when i try to execute the SQL procedure with cursor in ODI, I encountered error.
Do you have any idea how to do this? -
Stored procedure returning multiple records without using SYS_REFCURSOR
Hello,
I am new to oracle stored procedures, have done stored procs in SQL server in past. I am trying to write single stored proc which will return multiple records. I have the stored proc as below and that is compiled without any errors.
We don't want to use SYS_REFCURSOR as output param b'coz the place from which this proc is gonna call, that system doesn't support SYS_REFCURSOR param.
create or replace
PROCEDURE p_get5500DATA_MB (
IN_plan_ID IN T_5500DATA_QWP.Plan_ID%TYPE,
IN_plan_ID_col OUT T_5500DATA_QWP.Plan_ID%TYPE,
p_SEQNUM OUT T_5500DATA_QWP.SEQNUM%TYPE,
p_HEADER_CD OUT T_5500DATA_QWP.HEADER_CD%TYPE,
p_VALUE1 OUT T_5500DATA_QWP.VALUE1%TYPE,
p_VALUE2 OUT T_5500DATA_QWP.VALUE2%TYPE
) AS
BEGIN
SELECT
Plan_ID,
SEQNUM,
HEADER_CD,
VALUE1,
VALUE2
INTO
IN_plan_ID_col,
p_SEQNUM,
p_HEADER_CD,
p_VALUE1,
p_VALUE2
FROM TRS1DBO.T_5500DATA_QWP
WHERE Plan_ID = IN_plan_ID
ORDER BY SeqNum;
-- EXCEPTION
-- WHEN OTHERS THEN
-- RAISE_APPLICATION_ERROR(-210001, 'Error in fetching data from T_5500DATA_QWP....');
END;
Error:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "TRS1DBO.P_GET5500DATA_MB", line 10
ORA-06512: at line 11
My questions is:
- What would be the best practice for this type of simple stored procedures?
- Is there any alternate or is there anything i can fix in above stored proc which return multiple records?
Thank you,
VimalJust out of curiosity, what are you using for API or driver that doesn't support a ref cursor? Ref cursors are pretty much the defacto standard for passing multiple records out of an Oracle procedure. Oracle's ODP.NET, OLEDB, ODBC, JDBC, OCI, all support ref cursors. Chances are that if the driver you're using doesn't support something as basic/fundamental as a ref cursor, it's probably also not going to support something else either.
You'll most likely want to check with the driver/api vendor on their recommended approach. -
Calling SQL Stored Procedure using Oracle Gateway
Hi
Do you know how i can call a stored procedure with parameters from Oracle using oracle gateway?Don't know which gateway you are using. Only the transparent gateway for SQL Server and Sybase that have support for stored procedures.
Take a look at case 7 which shows how to do this.
Rem case7.sql
Rem
Rem Copyright (c) Oracle Corporation 2000. All Rights Reserved.
Rem
Rem NAME
Rem case7.sql
Rem
Rem DESCRIPTION
Rem SQL script which executes the demo case7 for the
Rem Transparent Gateways
Rem
Rem NOTES
Rem The database link GTWLINK should be created before you can
Rem run this demo file
Rem
Rem MODIFIED (MM/DD/YY)
Rem kpeyetti 11/09/00 - Created
Rem
SET ECHO ON
DROP TABLE LOCAL_GTW_DEPT;
CREATE TABLE LOCAL_GTW_DEPT (DEPTNO INTEGER, DEPTNAME VARCHAR2(14));
SELECT * FROM LOCAL_GTW_DEPT;
DECLARE
DNAME VARCHAR2(14);
BEGIN
"GetDept"@GTWLINK(10,DNAME);
INSERT INTO LOCAL_GTW_DEPT VALUES (10, DNAME);
END;
SELECT * FROM LOCAL_GTW_DEPT; -
With JDBC, calling a stored procedure with ARRAY as out parameter
Hi,
I want to use the data type ARRAY as an out parameter in an Oracle stored procedure. I want to call the stored procedure from
my java program using JDBC.
The problem it's i use a 8.1.7 client to acces with oci to a 7.1.3 Database.
With this configuration I can get back a Cursor but not an Array.
Does it's possible ?
Thanks for your help !
MichaklOriginally posted by JDBC Development Team:
It's very similar to other datatype except that it uses OracleTypes.ARRAY typecode and the value is mapped to a oracle.sql.ARRAY instance. The code looks as follows --
cstmt.registerOutParameter (idx, OracleTypes.ARRAY, "VARRAY_TYPE_NAME_HERE");
cstmt.execute ();
ARRAY array = (ARRAY) cstmt.getObject (idx);
Thanks for your reply.
I have to use:-
OracleCallableStatement cs1 = (OracleCallableStatement )conn.prepareCall
( "{call proj_array(?)}" ) ;
for retrieving a collection as an OUT parameter.
This gives me the errors:-
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Blob getBlob(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Array getArray(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Clob getClob(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Ref getRef(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
How do I get rid of these errors?
null -
Calling a stored procedure with VARRAY as out parameter using JDBC
Hi,
I want to use the data type VARRAY as an out parameter in an Oracle stored procedure. I want to call the stored procedure from
my java program using JDBC.
I'm using Oracle 8.1.5 for Windows NT.
Please help me.
Thanks
Sumanta
nullOriginally posted by JDBC Development Team:
It's very similar to other datatype except that it uses OracleTypes.ARRAY typecode and the value is mapped to a oracle.sql.ARRAY instance. The code looks as follows --
cstmt.registerOutParameter (idx, OracleTypes.ARRAY, "VARRAY_TYPE_NAME_HERE");
cstmt.execute ();
ARRAY array = (ARRAY) cstmt.getObject (idx);
Thanks for your reply.
I have to use:-
OracleCallableStatement cs1 = (OracleCallableStatement )conn.prepareCall
( "{call proj_array(?)}" ) ;
for retrieving a collection as an OUT parameter.
This gives me the errors:-
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Blob getBlob(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Array getArray(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Clob getClob(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Ref getRef(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
import java.sql.*;
^
How do I get rid of these errors?
null -
Calling a stored procedure for each row returned
I need to call a stored procedure for each row returned by a repeating frame. I called the stored procedure from the repeating frame format trigger, but that did not work( it did no populated the tables populated by the stored procedure)
How can I call a stored procedure for each row returned by a repeating frame.
Thank youInclude it as a formula column in your data model.
-
ORA-03115 error when calling a Stored Procedure
Hi All,
I'm in the process of porting a Pro/C app from NT to Linux. I've installed 8.1.5 on our Linux box and patched it up to 8.1.5.02.
It all kind of works ok, except that I'm sometimes getting ORA-03115 errors when the app calls a stored procedure. The call in question looks like this:
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR resprows[50][3998];
int numret = 0;
int numrows= 50;
int done= 0;
unsigned long resp_id = 0;
EXEC SQL END DECLARE SECTION;
EXEC SQL AT DB_NAME EXECUTE
BEGIN pkg_something.getdata(
:resp_id, /* IN */
:numrows, /* IN */
:done, /* OUT */
:resprows, /* OUT */
:numret /* OUT */
END;
END-EXEC;
The stored procedure basically uses the resp_id value to select rows from a table;
in each row there is a VARCHAR2(4000) column which it copies into the hostarray resprows.
There may be anything from 1 to numrows returned from the SP.
Initially, the resprows rows were defined to be size [4000]. Unfortunately, this caused ORA-02005 errors - I then changed the size to [3998], which seemed to fix the 02005's (although I'm unclear as to the reasons why).
Now I'm getting the 03115 errors when calling the SP. The oracle manual is not very helpful on what this error means.
This all works chipper on NT.
Any ideas?
Thanks in advance,
Nigel.
PS: The database the app is talking to is still hosted on NT.
nullHiston FTM wrote:
ORA-04063: package body "LAZARUS.LAZARUS" has errors Above, obviously conflicts with the statement that follows:
>
The procedure and package have both compiled without errors and the statement on its own works fine in SQL*Plus.I suggest you take a look in the USER_ERRORS view to see, what the errors are.
And just checking:
You have schema called LAZARUS, which holds a package named LAZARUS, which holds a procedure called POPULATEGRIDPOSITIONS?
Edited by: Toon Koppelaars on Oct 1, 2009 5:55 PM -
Calling a Stored Procedure with Parameter using an UDF
Hi All,
I have a requirement where I need to use database lookup. In that I am calling the Stored Procedure using UDF. For example sp_flow ., for this I have to pass<INTID> and <USDERID> to get the response.
I am using the below code to excute this.
Channel channel = null;
Map rowMap = null;
DataBaseAccessor accessor = null;
DataBaseResult resultSet = null;
String Query = null;
//Query ="EXECUTE dbo.sp_flow <INTID> <USERID>;
Query = "EXECUTE dbo.sp_flow \'304\' , \'shankar\' " ;
try{
//Determine a channel, as created in the Configuration
channel =
LookupService.getChanne"BS_XXX","CC_XXX_JDBC_Rcv");
//Get a system accessor for the channel. As the call is being made to an
DB, an DatabaseAccessor is obtained.
accessor = LookupService.getDataBaseAccessor(channel);
//Execute Query and get the values in resultset
resultSet = accessor.execute(Query);
for(Iterator rows = resultSet.getRows();rows.hasNext();){
rowMap = (Map)rows.next();
result.addValue((String)rowMap.get("FLOW_ID"));
I am getting the error "Error when calling an adapter by using the communication channel CC_NWLS_TLA_JDBC_Rcv (Party: , Service: BS_MICROSOFT_SQLWLS20DEV_D, Object ID: d30aace599de3cd69548bf145d0724b7) XI AF API call failed. Module exception: (No information available). Cause Exception: 'Error processing request in sax parser: Error when executing statement for table/stored proc. 'table' (structure 'statement'): com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set."
let me know how do this.
Regards
shankar
Edited by: Shankar on Jun 9, 2009 2:51 PM
Edited by: Shankar on Jun 9, 2009 3:02 PMfirst of all calling a SP via the lookup API, there is a workaround but it is not at all recommended
FYI
/people/arpil.gupta/blog/2008/11/03/workaround-for-jdbc-scenarios - DB Lookup via Stored procedure
http://help.sap.com/javadocs/NW04S/current/pi/com/sap/aii/mapping/lookup/DataBaseAccessor.html
The accessor does not support transactional behaviour. Therefore, the method should not be used to execute insert or update statements on the database which can lead to inconsistencies. The accessor should only be used to read data from a database table. -
Calling of Stored Procedure in After Insert Trigger
Can I call a Stored Procedure in After Insert Trigger ?
Please send a sample code (good example) of After Insert Trigger.
Thanks.Kishore,
I have two table WLCS_ORDER, WLCS_ORDER_LINE
WLCS_ORDER - It holds order header information like
ORDER_ID
CUSTOMER_ID
TRANSACTION_ID
STATUS
ORDER_DATE
SHIPPING_METHOD
SHIPPING_AMOUNT
SHIPPING_CURRENCY
PRICE_AMOUNT
PRICE_CURRENCY
SHIPPING_GEOCODE
SHIPPING_STREET1
SHIPPING_STREET2
SHIPPING_CITY
SHIPPING_STATE
SHIPPING_COUNTRY
SHIPPING_POBOX
SHIPPING_COUNTY
SHIPPING_POSTAL_CODE
SHIPPING_POSTAL_CODE_TYPE
SPECIAL_INSTRUCTIONS
SPLITTING_PREFERENCE
ORDER_SUBTOTAL
WLCS_ORDER_LINE - It holds all order lines information like
ORDER_LINE_ID
QUANTITY
PRODUCT_ID
TAX_AMOUNT
TAX_CURRENCY
SHIPPING_AMOUNT
SHIPPING_CURRENCY
UNIT_PRICE_AMOUNT
UNIT_PRICE_CURRENCY
MSRP_AMOUNT
MSRP_CURRENCY
DESCRIPTION
ORDER_ID
TOTAL_LINE_AMOUNT
Relation between WLCS_ORDER, WLCS_ORDER_LINE is one to many.
For each WLCS_ORDER row, one or more order lines will insert into WLCS_ORDER_LINE table.
For each new row in WLCS_ORDER table, I have to update the following columns in both the tables with my maths.
WLCS_ORDER
shipping_amount
price_amount
order_subtotal
WLCS_ORDER_LINE
shipping_amount
I thought I can do this in after insert trigger, But if it is not possible, Please give the best way to fulfill this requirement.
I appreciate your help.
Have a great day.
Srinivas -
Errors in calling Oracle stored procedure using java CallableStatement
Hello,
I have an oracle stored procedure below, it has been tested in PL/SQL without errors. During testing, in_c_file_type="F"; out_n_seqno_freeformat=120139596 and out_n_seqno_commaseprated is null (empty in value column).
When I run the program in Eclipse (windows xp), error messages is below: (It stopped at line 'cstme.execute();' )
Message:ORA-06550: line 1, column 26: PLS-00103: Encountered the symbol "" when expecting one of the following: . ( ) , * @ % & | = - + < / > at in is mod remainder not range rem => .. <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ as between from using || indicator multiset member SUBMULTISET_ The symbol ", was inserted before "" to continue. Error code:6550 SQL statement:65000 {code} Does anyone know what cause the error? It seems like something is missing in the stored procedure. But the stored procedure passes the test in the PL/SQL. The oracla driver I used is Oracle thin driver. Oracle version is 10.2.g Thanks in advance. northcloud {code} create or replace procedure SP_GET_SEQNO_2( in_c_file_type in char, out_n_seqno_freeformat out integer, out_n_seqno_commaseprated out integer) is n_seqno_commaseprated integer; n_seqno_freeformat integer; begin if in_c_file_type ='F' THEN SELECT message_counter.nextval INTO n_seqno_freeformat FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_freeformat,empty_clob(),empty_clob()); elsif in_c_file_type ='C' THEN SELECT message_counter.nextval INTO n_seqno_commaseprated FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_commaseprated,empty_clob(),empty_clob()); else SELECT message_counter.nextval INTO n_seqno_freeformat FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_freeformat,empty_clob(),empty_clob()); SELECT message_counter.nextval INTO n_seqno_commaseprated FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_commaseprated,empty_clob(),empty_clob()); end if; out_n_seqno_freeformat := n_seqno_freeformat; out_n_seqno_commaseprated := n_seqno_commaseprated; end SP_GET_SEQNO_2; {code} ----- A part of java code I used to call the stored procedure is here. {code} String escapeString = "{call SP_GET_SEQNO_2 (? ? ?)}"; CallableStatement cstme = null; try { cstme = con.prepareCall(escapeString); cstme.setString(1, "F"); cstme.registerOutParameter(2, java.sql.Types.INTEGER); cstme.registerOutParameter(3, java.sql.Types.INTEGER); cstme.execute(); int seqNoFreeformat=0, seqNocommasepreted=0; seqNoFreeformat = cstme.getInt(2); seqNocommasepreted = cstme.getInt(3); System.out.println ("In ConvertXML.processStoredProcedure(), seqNoFreeformat= "+seqNoFreeformat+";seqNocommasepreted="+seqNocommasepreted); } catch (SQLException e) { //System.out.println ("In ConvertXML.processStoredProcedure(), SQLException: "+e); System.err.println("Message:"+e.getMessage()); System.err.println("Error code:"+e.getErrorCode()); System.err.println("SQL statement:"+e.getSQLState()); log.log(Level.INFO, log.getName() + " - SQLException : "+e); } {code}es5f2000 wrote:
jschell wrote:
That works?I dunno. The below definitely works, but like I said, I've only
ever done it with one output parameter (and that has always
been a ResultSet).
String callableQuery = "{?= call my_package.my_call(?, ?)}"
Yes I have done that and at least in terms of my code it wasn't just a result set.
But not with two. -
Forms - Calls to stored procedures instead of standard database actions
After discovering Reports, I'm now getting started with Forms in APEX. :)
While I like the basic functionalities offered by the different Wizards, there's one thing that bothers me. After creating your form, you basically get 3 buttons (not counting cancel) for the different actions, each corresponding with a Database Action (SQL INSERT/UPDATE/DELETE). This is nice, but it's not exactly what I want. I would like to replace the direct database actions by calls to stored procedures (in a package), one for each action. It would be nice, of course, to keep the Wizard advantages, especially considering the fact I would like to find a standard, easy way to create forms. So, basically, I would like to create my forms this way, but instead of linking the button to a predefined database action, have it call a stored procedure. Is this somehow possible and what would be the easiest way to realize this?
I'm running APEX 4.0.1.00.03 on an Oracle XE database.
ErwinOkay, this was working nicely. But I must be missing something...
I made an (interactive) report and added two link columns, one for the update and one for the delete (the insert is handled by a non-row related create button). I also created 3 forms on a procedure, one for each action (I/U/D). Now, when I call my form page from the report, I want to pass the values of the different columns of the selected record to this form, so the user can view and adapt them. Seems quite logical to me. There's only one problem. The column link seems to be limited to 3 items? Euh... am I missing something or is this not the way to do this.
Let me illustrate this with an example.
I created an UPDATE form, linked to a procedure to modify a given city.
This procedure has the following parameters:
- ID (hidden on the form)
- PROVINCE
- ZIP CODE
- NAME
- DESCRIPTION
On the other hand, I have my report which gives an overview of the cities. This report has the following columns:
- ID
- PROVINCE
- ZIP CODE
- NAME
- DESCRIPTION
I also added 2 empty columns to contain the UPDATE and DELETE links. Basically, I just use these to place a nice icon for the different actions.
Now, when I click on one of these icons, I want to pass the field values of the selected row to my form. In this case, that means I want to pass 5 values to the 5 items of my form. BUT, under the link column, I see only 3 items? Am I missing something really stupid or am I handling this the wrong way?
Erwin -
Calling db2 stored procedures from wls 8.1 sp2
Hi,
We noticed strange behaviour when moving customers applications from wls 6.1 to 8.1 sp2. We have a use case where we call db2 stored procedure two times (same prcedure) to make inserts to a database. The first time when procedure is called, everything goes smoothly but at the second time db2 claims that statement is not prepared and gives us sql error sql0518n.
We do see this error only if we use wls prepared statement cache and without cache (size=0) everything seems to work. We also did some db2 level tracing and noticed that statement is not prepared when using wls cache and db2 cannot execute statement which is not prepared....
Why I'm asking this? because this is the first time I had disable wls cache. We have used it and even optimized software performance using prepared statement cache in several projects before this.
Procedure call is done from web container lavel and no EJBs is used. We have tested the use case using autommit option and also committed firts transaction manually and closed connection.
We are using DB2 8.2 fp7 as a database and IBM level 2 JDBC driver without XA support. Honor global transactions support is on at a datasource.
Is this normal behaviour? Db2 problem or maybe WLS problem?
Regards,
MikaI am getting the same exception about an assertion failed at weblogic.t3.srvr.T3Srvr.checkServerLock. Any ideas?
-
SQLException while calling a Stored Procedure in Oracle
Hi all,
I am getting this error while calling a Stored Procedure in Oracle...
java.sql.SQLException: ORA-00600: internal error code, arguments: [12259], [], [
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:207)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:540)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1273)
at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:780)
at oracle.jdbc.driver.OracleResultSet.next(OracleResultSet.java:135)
at StoredProcedureDemo.main(StoredProcedureDemo.java:36)
The Program is ...
import java.sql.*;
public class StoredProcedureDemo {
public static void main(String[] args) throws Exception {
Connection con = null;
ResultSet rs = null;
Statement st = null;
CallableStatement cs = null;
int i;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:SHYAM","scott","tiger");
System.out.println("Got Connection ");
st = con.createStatement();
String createProcedure = "create or replace PROCEDURE Get_emp_names (Dept_num IN NUMBER) IS"
+" Emp_name VARCHAR2(10);"
+" CURSOR c1 (Depno NUMBER) IS"
+" SELECT Ename FROM emp WHERE deptno = Depno;"
+" BEGIN"
+" OPEN c1(Dept_num);"
+" LOOP"
+" FETCH c1 INTO Emp_name;"
+" EXIT WHEN C1%NOTFOUND;"
+" END LOOP;"
+" CLOSE c1;"
+" END;";
System.out.println("Stored Procedure is \n"+createProcedure);
i = st.executeUpdate(createProcedure);
System.out.println("After creating the Stored Procedure "+i);
cs = con.prepareCall("{call Get_emp_names(?)}");
System.out.println("After calling the Stored Procedure ");
cs.setInt(1,20);
System.out.println("Before executing the Stored Procedure ");
rs = cs.executeQuery();
System.out.println("The Enames of the given Dept are ....");
while(rs.next()) {
System.out.println("In The while loop ");
System.out.println(rs.getString(1));
catch (Exception e) {
e.printStackTrace();
Stored Procedure is ...
create or replace PROCEDURE Get_emp_names (Dept_num IN NUMBER) IS
Emp_name VARCHAR2(10);
CURSOR c1 (Depno NUMBER) IS
SELECT Ename FROM emp WHERE deptno = Depno;
BEGIN
OPEN c1(Dept_num);
LOOP
FETCH c1 INTO Emp_name;
EXIT WHEN C1%NOTFOUND;
END LOOP;
CLOSE c1;
END;
Stored procedure is working properly on sql*plus(Oracle 8.1.5)) editor. But it is not working from a standalone java application. Can anyone please give me a solution.
thanks and regards
Shyam KrishnaThe first solution is to not do that in java in the first place.
DDL should be in script files which are applied to oracle outside of java.
Other than I believe there are some existing stored procedures in Oracle that take DDL strings and process them. Your user has to have permission of course. You can track them down via the documentation. -
Calling a stored procedure from a url
I am needing to call a stored procedure from a url string (or
anchor) understand that from training to be as follows:
http://host:port/pls/dad/package.procedure?query_string
With that in mind, I am getting an error as follows:
Not Found
The requested URL /pls/portal30/at_hrfm.checkshow.showcheck was
not found on this server.
Here is a sample of my url
http://servername:port/pls/portal30/at_hrfm.checkshow.showcheck
I can see servername:port/pls/portal30, it is just the
procedure I am having a problem with.
Here is a sample of my source code that is created under the
at_hrfm schema (I also tried under portal30 schema).
package body checkshow as
procedure showcheck as
begin
htp.htmlOpen;
htp.headOpen;
htp.title('My Check');
htp.comment ('This should be your Check');
htp.bodyOpen;
htp.header (1,'Check');
htp.print ('checkdate');
htp.bodyClose;
htp.headClose;
htp.htmlClose;
end;
end;I think I figured this out. I don't think the grant to ANONYMOUS is going to work with production XE and the online documentation is in need of an update. It appears that production XE has been locked down and you will need to specify the name of each stored procedure you wish to allow to be executed by adding it to the WWV_FLOW_EPG_INCLUDE_MOD_LOCAL function. This is spelled out in more technical detail here: http://download.oracle.com/docs/cd/B25329_01/doc/appdev.102/b25309/adm_wrkspc.htm#BEJCGJFJ
Another alternative that would work involves creating a separate DAD. Using the DAD approach with my schema made all of my stored procedures callable from a web browser, so I rejected this approach. To make this usable (secure) I would have needed to create and maintain a separate database user for the DAD and then only granted it execute for the stored procedures I wanted to be callable from a URL.
Finally I read about using an on-demand procedure and having it invoke the desired stored procedure. While I didn't try this out, it sounds like another good approach because it maintains session security. If it can be used to return an image I do not know.
- Jim
Maybe you are looking for
-
IDM 8.1 deprovisioning of domino user thowing error
Hi, I am using Sun IDM 8.1. I configured Lotus Domino as an resource. I am able to do the following successfully. 1) Creation of a user 2) Modification 3) Change password I am facing problem in deprovisioning or deleting a user from the resouce. Erro
-
Only half the keyboard works after sleep
I have a fall 2011 Air running Lion. It has a weird problem: sometimes (maybe 1 out of 10), after waking up from sleeping (closing the case - I haven't tried manually putting it to sleep - only the left hand portion of the keyboard works. At the logi
-
Constantly asking for password
My school email account has limits on how often the box can be checked. When Mail checks this account before the time limit has passed, it is denied access and seems to think that my password was incorrect. Of course even after my password has been e
-
How do I get the system's locale information in Java. I'm using a linux m/c if that helps. thanks
-
Hi I want to display text dynamically on the stage e.g When I click mouse first time its should display " this is the first click" and second time " this is the second clik" and so on. Can someone help me with the code here.