JDBC result set from an Oracle PL/SQL stored procedure
Could you please let us know the difference between oracleClose() and oracleCloseQuery() in sqlj.runtime.ExecutionContext.OracleContext. Since we upgraded jdbc driver jar to ojdbc5.jar with the oracleClose() we get the below exception and not with oracleCloseQuery(). Is it safe to use oracleCloseQuery(). The database is Oracle 11g and WAS 6.1.X.X
java.sql.SQLException: Closed Statement: next
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:131)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:197)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:269)
at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:205)
at com.westgroup.pubsvc.rms.models.ResultSetSRC.getNextResult(ResultSetSRC.java:112)
http://forums.oracle.com/forums/ann.jspa?annID=599
Similar Messages
-
JDBC Result Set from Non-Database Source
In Java, is it possible to create a result set from a non-database data source?, for example an XML file, text file, vectors, java beans
We have a Swing application that currently makes direct JDBC calls to the DB2 database for creating result sets. We want to replace JDBC calls with calls to web service, but want to still create result sets on the client, so the replacement of the datasource from database to web service call is transparent to the rest of the code.In Java, is it possible to create a result set from a
non-database data source?, Yes.
for example an XML file,
text file, vectors, java beans
We have a Swing application that currently makes
direct JDBC calls to the DB2 database for creating
result sets. We want to replace JDBC calls with calls
to web service, but want to still create result sets
on the client, so the replacement of the datasource
from database to web service call is transparent to
the rest of the code.You might want to think carefully about what you are doing.
It is fairly easy, although somewhat tedious (many methods,) to create a new type of ResultSet.
But if the above application is doing SQL via statements and expecting the result via a ResultSet then you are not just creating a ResultSet but an entire driver and one that will have to deal with SQL as well. And if you have to handle the SQL itself that means you will probably need a parser and interpreter. -
ICommand FixedQueryWithOutput Oracle PL/SQL Stored Procedure
Assume a stored procedure, delivered in a package....
user.package.storedproc( input-parameter, input-output cursor )
If a "FixedQueryWithOutput" is used to run this procedure.....
user.package.storedproc( '[Param.1]', ? )
The procedure runs correctly, and returns valid output (assuming that query template has valid data in the "parameters" tab).
Further, if the stored-procedure/query-template is wired into an iCommand applet that has a Param value explicitly specified...
<applet name = "PMilestoneApplet"
width = "1"
height = "1"
code = "iCommand"
codebase = "/Illuminator/Classes"
archive = "illum8.zip" mayscript>
<param name = "QueryTemplate"
value = "Ipath/to/template/file" />
<param name = "Param.1"
value = "DXBP004500" />
</applet>
The web page that uses the iCommand sucessfully retrieves the expected data.
If I attempt to modify the parameter through JavaScript...
var CmdApplet02 = document.PMilestoneApplet ;
var commandObject02 = CmdApplet.getQueryObject() ;
commandObject02.setParam( 1, "DXBP004800" ) ;
if ( ! CmdApplet02.executeCommand() )
<do something to handle error>
The iCommand runs sucessfully, but returns no data. I have used "commandObject02.getParam(1)" as a sanity check to fetch/display the parameter before and after the call to iCommand, and the data is as expected.
If I provide a default value for the parameter within the applet, the applet returns data associated with the default-parameter, not with the parameter dynamically set with JavaScript.
It begins to look as if the iCommand will not process parameters within a FixedQueryWithOutput (I have sucessfully used iCommand to set the parameters on "normal" queries).
PS...I owe thanks to all of you who have responed to me in the past, and I wish I could assign points, but it seems that this Forum "forgets" who I am every couple of weeks, and I loose access to my previous posts!!Resolved through local maintenance
-
Pass date range parameter to SQL stored procedure.
Hi,
I'd like to pass a date range parameter from Crystal Reports to a sql stored procedure. Does anyone know if this is possible?
I've had no problem passing standard datetime (single value) paramaters to and from but am struggling with getting a range value parameter to work.
Environment: Crystal Reports 10/XI and SQL 2000 MSDE version or SQL 2005 Express Edition.
Any help would be appreciated.C5112736 wrote:>
> And then these 2 formulas 'Formula # 1' and 'Formula # 2' can be used to pass on to the stored procedure.
Can someone please demonstrate exactly how to use formula results as date parameters to a SQL stored procedure? Keep in mind, there are two parameters to the stored procedure.
I have gleaned this much: Use Add Command and insert the procedure with
EXEC ServerName.dbo.usp_sprocName;1 '{?StringParameter}'
but if I try to do
{CALL ServerName.dbo.usp_SprocName({@Formula1},{@Formula2})}
then it gives the error "No value given for one or more required parameters".
Both of the parameters are VARCHAR(50).
I have finally found this link: [http://msdn.microsoft.com/en-us/library/ms710248(VS.85).aspx|http://msdn.microsoft.com/en-us/library/ms710248(VS.85).aspx]
This Microsoft site defines the format of the ODBC escape sequences, but I still do not know how to convince Crystal to insert it's parameter results or formula results.
Pulling what's left of my hair out . . .
~ Shaun -
How to export result set from mysql query browser to .sql in oracle
Hi folks:
I was trying to export result set from MySql query browser to Oracle. I could able to do
File->Export Result Set-> Excel format...
What I am trying to get is .sql file so that I can run it as a script in my oracle db. Is there any way we can get .sql file with inserts and delimeters ....?
Did you guys get my question.?
Please throw some light on this....
Could be very appreciable ....
Thanks
Sudhir NaiduHi
Create a sql statement which generates the insert statements.
Something like this:
select 'insert into table1 (column1, column2, column3) values (' ||
column1 || ', ' || column2 || ', ' || column3 || ');' from table 1;
The || sign is the string concatenation sign in Oracle, replace it the appropriate sign in MySql. Export the result set of this query into a file, and you can run it in a SqlPlus.
Ott Karesz
http://www.trendo-kft.hu -
Performance to fetch result set from stored procedure.
I read some of related threads, but couldn't find any good suggestions about the performance issue to fetch the result set from a stored procedure.
Here is my case:
I have a stored procedure which will return 2,030,000 rows. When I run the select part only in the dbartisan, it takes about 3 minutes, so I know it's not query problem. But when I call the stored procedure in DBArtisan in following way:
declare cr SYS_REFCURSOR;
firstname char(20);
lastname char(20);
street char(40);
city char(20);
STATE varchar2(2);
begin DISPLAY_ADDRESS(cr);
DBMS_OUTPUT.ENABLE(null);
LOOP
FETCH cr INTO firstname,lastname,street, city, state;
EXIT WHEN cr%NOTFOUND;
DBMS_OUTPUT.PUT_LINE( firstname||','|| lastname||','|| street||',' ||city||',' ||STATE);
END LOOP;
CLOSE cr;
end;
It will take about 100 minutes. When I used DBI fetchrow_array in perl code, it took about same amount of time. However, same stored procedure in sybase without using cursor, and same perl code, it only takes 12 minutes to display all results. We assume oracle has better performance. So what could be the problem here?
The perl code:
my $dbh = DBI->connect($databaseserver, $dbuser, $dbpassword,
{ 'AutoCommit' => 0,'RaiseError' => 1, 'PrintError' => 0 })
or die "couldn't connect to database: " . DBI->errstr;
open OUTPUTFILE, ">$temp_output_path";
my $rc;
my $sql="BEGIN DISPLAY_ADDRESS(:rc); END;";
my $sth = $dbh->prepare($sql) or die "Couldn't prepare statement: " . $dbh->errstr;
$sth->bind_param_inout(':rc', \$rc, 0, { ora_type=> ORA_RSET });
$sth->execute() or die "Couldn't execute statement: " . $sth->errstr;
while($address_info=$rc->fetchrow_arrayref()){
my ($firstname, $lastname, $street, $city, $STATE) = @$address_info;
print OUTPUTFILE $firstname."|".$lastname."|".$street."|".$city."|".$STATE;
$dbh->commit();
$dbh->disconnect();
close OUTPUTFILE;
Thanks!
rulinThanks for you reply!
1) The stored procedure has head
CREATE OR REPLACE PROCEDURE X_OWNER.DISPLAY_ADDRESS
cv_1 IN OUT SYS_REFCURSOR
AS
err_msg VARCHAR2(100);
BEGIN
--Adaptive Server has expanded all '*' elements in the following statement
OPEN cv_1 FOR
Select ...
commit;
EXCEPTION
WHEN OTHERS THEN
err_msg := SQLERRM;
dbms_output.put_line (err_msg);
ROLLBACK;
END;
If I only run select .. in DBArtisan, it display all 2030,000 rows in 3:44 minutes
2) But when call stored procedure, it will take 80-100 minutes .
3) The stored procedure is translated from sybase using migration tools, it's very simple, in sybase it just
CREATE PROCEDURE X_OWNER.DISPLAY_ADDRESS
AS
BEGIN
select ..
The select part is exact same.
4) The perl code is almost exact same, except the query sql:
sybase verson: my $sql ="exec DISPLAY_ADDRESS";
and no need bind the cursor parameter.
This is batch job, we create a file with all information, and ftp to clients everynight.
Thanks!
Rulin -
Need help in restricting a result set from a UNION in MERGE
Hello,
Would really appreciate if anybody could help me out with the issue I am facing with the below statements (I am new to Oracle ):
merge into table_name_1 p
using
select p_key, value_1, value_2
from some_tables
UNION
select p_key, value_1, value_2
from some_tables
UNION
)t
on (p.p_key = t.p_key)
when matched then
update table_name_1 with value_1 and value_2
when not matched then
insert table_name_1 with p_key, value_1, value_2;
Now, the union of all those selects gives me distinct values and it works most of the times but when I get values like below, the merge fails:
p_key-----value_1-----value_2
100-----25-----50
100-----NULL-----50
I browsed the net and understood the reason behind this: the result set becomes ambiguous and merge doesn't know which row to insert first and which one to update.
Now, my requirement is: I could have any of the below scenario/result sets from the union and I need only 1 row per p_key -
result_set_1
p_key-----value_1-----value_2
100-----25-----50 ***************need this row
100-----NULL-----50
100-----NULL-----NULL
result_set_2
p_key-----value_1-----value_2
100-----25-----NULL ***************need this row
100-----NULL-----NULL
result_set_3
p_key-----value_1-----value_2
100-----25-----NULL ***************need this row (p_key = 100)
100-----NULL-----NULL
200-----NULL-----75 ***************need this row (p_key = 200)
200-----NULL-----NULL
300-----90-----95 ***************need this row (p_key = 300)
So, I basically need a way to restrict the values that I will get from the UNION of all those selects to fit the requirement above, hope I was able to explain the issue I am facing.
Any help would be greatly appreciated.
Thanks,
DpunkIn all cases the goal is to find an order by value that will make the row you want be first.
The query I gave is calculating a priority for each row by adding up values showing whether each column is null or not null. The case statements check whether each column is null and need to be added up to give a total priority value.
Value_1 Value_2 Priority
Not Null Not Null 2 + 1 = 3
Not Null Null 2 + 0 = 2
Null Not Null 0 + 1 = 1
Null Null 0 + 0 = 0
The priority value ends up being a bitmap showing whether each value is null or not null. I think that reflects my mathematics background.
Another way of getting the same result (suggested to me by your asking why it needs the "+") would be to use two CASE expressions as separate order by items:
select p_key, value_1, value_2 from
(select p_key, value_1, value_2, row_number() over
(partition by p_key
order by case when value_1 is null then 0 else 1 end DESC,
case when value_2 is null then 0 else 1 end DESC
) as rn
from (your UNION query here)
where rn = 1
A third way is to use a more complex case statement:
select p_key, value_1, value_2 from
(select p_key, value_1, value_2, row_number() over
(partition by p_key
order by case when value_1 is NOT null and value_2 is NOT null then 1
when value_1 is NOT null and value_2 is null then 2
when value_1 is null and value_2 is NOT null then 3
when value_1 is null and value_2 is null then 4
end ASC
) as rn
from (your UNION query here)
where rn = 1 -
It is required to get the result set from the last query.
I need this SP to return the result set from the last query.
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
alter proc spQ_GetASCBillingRateIDs2
@ScheduleID CHAR(15),
@startdate smalldatetime,
@enddate smalldatetime
as
set nocount on
truncate table tbltmpgroup
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tbltmptbltest]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tbltmptbltest]
exec sp_CreateTblTmpGroup
insert into tbltmpgroup
SELECT DISTINCT
case when pd.billparent = 'N' then org.eligibleorgid
else isnull(af.parentid, org.eligibleorgid) end as billorgid,
pd.individualbill , pd.cobrabill, pd.billparent,
org.eligibleorgid, org.polid, org.orgpolicyid,
pp.planid, pp.rateid,
ps.ascinvoicedate,
case when ps.ascclaimfromdate > @startdate then ps.ascclaimfromdate
else @startdate end as premiumrundayFrom,
case when ps.ascclaimtodate < @enddate then ps.ascclaimtodate
else @enddate end as premiumrundayTo,
fts.effdate, fts.termdate,
case when fts.effdate > @startdate then fts.EffDate
else @startdate end as ascStartDate,
case when fts.termdate < @enddate then fts.termdate
else @enddate end as ascEndDate
FROM premiumschedule ps (nolock)
inner join orgpolicy org (nolock)
on org.ascinvoicerungroup between ps.premiumrundayfrom and ps.premiumrundayto
inner join FundingTypeStatus fts
on fts.orgpolicyid = org.orgpolicyid
and fts.fundtype = 'ASC'
and ((fts.effdate between @startdate and @enddate)
or (fts.termdate between @startdate and @enddate)
or (fts.effdate < @startdate and fts.termdate > @enddate))
inner join eligibilityorg o (nolock)
on org.eligibleorgid = o.eligibleorgid
inner join policydef pd (nolock)
on pd.polid = org.polid
inner join policyplans pp (nolock)
on pp.polid = org.polid
inner join program p (nolock)
on pd.programid = p.programid
left join orgaffiliation af with (nolock)
on org.eligibleorgid = af.childid
WHERE ps.premiumscheduleid = @ScheduleID
AND org.orgpolicyid <> ''
go
SELECT DISTINCT z.rateid, e.enrollid, z.ascstartdate, z.ascenddate
into tbltmptbltest FROM enrollment E (nolock)
inner join tbltmpgroup z
on e.rateid = z.rateid
go
CREATE UNIQUE CLUSTERED INDEX IDXTempTable ON tbltmptbltest(enrollid)
create index IDXTemptableDates on tbltmptbltest(ascstartdate,ascenddate)
go
select distinct t.*
from tbltmpgroup t
where rateid in (
select distinct t.rateid from VW_ASC_Billing)
order by billorgid
set nocount off
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GOPlease post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules (you have no idea).
Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
What you did post is bad SQL.
The prefix “tbl-” is a design flaw called tibbling and we do not do it. We seldom use temp tables in RDBMS; it is how magnetic tape file programmers fake scratch tapes.
If the schema is correct, then SELECT DISTINCT is almost never used.
Your “bill_parent” looks like a assembly language bit flag; we never use those flags in SQL.
“Funding_Type_Status” is an absurd name for a table. A status is a state of being, not an entity. A type is an attribute property. So this table ought to be column that is either a “funding_type” or “funding_status” (with the time period for the state of being
shown in other columns). But this hybrid is not possible in a valid data model.
Want to try again, with DDL and some specs?
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
How to send a Varying Array param to a PL/SQL Stored Procedure from Java
* I am VERY new to jdbc, and even somewhat new to Java
* I'm using Java 1.5, Oracle 10g.
* I need to call the following PL/SQL Stored Procedure from Java:
procedure setEventStatus
i_deQueueStatus in deQueueStatus_type
*deQueueStatus_type is the following (an array of deQueueStatus_OBJ):
CREATE OR REPLACE TYPE deQueueStatus_OBJ as object
eventID number (20),
dequeuestatus varchar2(20)
CREATE OR REPLACE TYPE deQueueStatus_TYPE IS VARYING ARRAY(500) of deQueueStatus_obj
*I have created a Java object as follows:
public class EventQueueDeQueueStatus
long eventID;
String dequeueStatus;
EventQueueDeQueueStatus(long eventID, String dequeueStatus)
this.eventID = eventID;
this.dequeueStatus = dequeueStatus;
I have an ArrayList of these.
I need to pass this list to the Stored Procedure. How do I create a java.sql.Array so I can call CallableStatement.setArray to set the parameter? Or do I use something else? I have tried setObject with both the ArrayList and also with a primitive array, but got "Invalid Column Type" both times.
Any help would be greatly appreciated. I just got this task today, and I have to make it work by Tuesday :-( !
Thanks,
KathyKathy,
Search the archives of this forum and the JDBC forum for the terms STRUCT and ARRAY and you can find some sample code on the JDBC How-To Documents page and the JDBC Samples which can both be accessed from this page:
http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html
Good Luck,
Avi. -
Executing a shell script from pl/sql stored procedure
Hi,
I have Oracle 8i on HP-UX.
I am passing a shell script name as a parameter to a user defined function from a pl/sql stored procedure. This user defined function has insterface to a user defined Java class file in Aurora java virtual machine which is written using runtime class which can execute any OS command or any shell script. I am getting any OS command run successfully, but could not run my own shell script. It's is not getting environment variables of my own, so not getting executed. So please suggest how can get these env variables in my shell script and also suggest other sucurity concerns to be taken into consideration.
If you have any questions please let me know.
This is really a very urgent issue.....
Please help me.
Thanks
Srinivasa Rao KollaYour best bet is to use the dbms_pipe builtin package to send the command to the host
-
APEX - accepting OUT variable values from PL/SQL Stored Procedure
I have created a page (Form) which is accepting values text fields.
In the Page Processing section under Processing, I am passing the values to a PL/SQL Stored Procedure, which acts like an API. The procedure contains code to validate the entered data and finally insert the data into the base tables. The procedure also contains OUT variables in the parameter that would return status of processing and any error messages.
Now, my question is, how can I make the page accept these OUT variables from the procedure. What I wish to do is, to capture these messages/processing status from the procedure in the page. For example, if there is a error in the data and the procedure is sending this message in the OUT variable, I need this to be displayed on the page as an error message.
Is this possible in APEX?
Regards,
Santhosh JoseHi VC,
I just tried putting the string directly instead of the variable. Its still not giving me the expected results.
HOWEVER, I think the reason was because of the EXCEPTION block in my code. I have an EXCEPTION block to handle exceptions. I commented the WHEN OTHERS section and now the error message is coming on the page.
So what I have done now is as follows: At the point at which the error is expected, I am raising a handled exception. And within the exception handling, I am giving RAISE_APPLICATION_ERROR.
WHEN ex_main_error*
THEN*
p_status := 2;*
p_msg := 'ERROR Stage: '||lc_err_stage||' ERROR Message: '||lc_err_msg;*
RAISE_APPLICATION_ERROR (-20001, p_msg);*
This is working now! Which is very good news. Thanks once again for your help!
Regards,
Santhosh Jose -
Does Oracle have Extended Stored Procedure like SQL Server and Sybase?
Hi, i am new to Oracle. I want to know if...
Does Oracle have Extended Stored Procedure like SQL Server and Sybase?
If it does not have, then how can i call outside program written in C or JAVA from the Database stored procedure or trigger?refer to this link on external procedures
http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a76956/manproc.htm#11064 -
Get server output from pl/sql stored procedure
Hi Colleagues,
I would like to get and watch the server output of my PL/SQL stored procedure
when I run my java program and call it from. The Stored proc. uses "dbms_output.put_line".
If it is clearly and possible (or not), will you send me your answer!
Thanks a lot
UlveHi,
You can redirect the standard output to the console (i.e., the SQL output) using the
DBMS_JAVA.SET_OUTPUT() method.
SQL> SET SERVEROUTPUT ON
SQL> call dbms_java.set_output (5000);But, the output is only printed when the stored procedure exits, and this setting works only for one call (i.e., the SQL call that immediately follows the invocation of DBMS_JAVA.SET_OUTPUT()). The minumum and default value is 2,000 characters and the maximum is 1,000,000 (1 million) characters. Notice the “SET SERVEROUTPUT ON” which enables displaying the outputs of stored procedures (Java or PL/SQL blocks) in SQL*Plus.
Kuassi http://db360.blogspot.com -
How to write a PL/SQL stored procedure in Oracle to call Webservice
Can any one pelase send me a code on how to write a PL/SQL stored procedure in Oracle database to call the Webservice ?
Thanks,
RajeshWere you able to solve this problem
-
How to call pl/sql stored procedure in JDBC query dialogbox
Hi,
how to call pl/sql stored procedure in JDBC query dialogbox(reports 9i) .
Cheers,
Raghuplease refer : Re: problem If you have more doubts, please ask in that question.
Maybe you are looking for
-
ITunes and Quicktime - Movie requires Quicktime which is not supported
Ok. Issue is: Movies and TV shows bought thru iTunes (10.5.1) on Lion (10.7.2) generate an error at time of playback. Error is 'This movie requires QuickTime, which is not supported by this version of iTunes." Help documents state to switch to 32 b
-
Dear ALL, First let me tell you, i have searched the forum for the clue to the below topic. Could not find any clue. That's the reason am posting this question. and also know in sap std only 1:1 is possible. but would like to know, if anybody has enc
-
CAn anyone help me, speakers are both displayed on apple tv but cannot play both, appletv with speakers and a new tango air!
-
Can e-Recruitment produce a file on each application received i.e. a *.pdf or Word Document that can be downloaded to be emailed to non e-Recruitment users? Thanks WB
-
Hi experts, I have developed one report in smartforms and trying to printout on Dot matrix printer. When iam printing report(i have 5 pages) ,iam getting fine for first two pages.But third page onwords... few lines of third page are getting printed i