Returning the Array of Result Set
I am executing 3 SQL in a function in a Bean.I want this function to return all the 3 result set with a help of a singl return type.And extract the values of different result set in the JSP.How should i do this.CAn i make an Array of type ResultSet.
Please guide me.
The ideal solution is convert the resultset into a Collection object such as ArrayList and then transport it to the jsp layer. You cannot transport a resultset as it is associated with a connection object.
BTW, as many of us have pointed out in this forum, care should be taken to release all the JDBC resources ASAP. Hence my take on tis will be to iterate through the resultset and take the data to a collection and close the resultset and associated resources.
Cheers
Sekar
Similar Messages
-
API search will only return the first 200 results????
It seems that I can only retrieve 200 results when using doOracleSimpleSearch api call.
osr = oses.doOracleSimpleSearch(strSearch, 1, 1000, false, false, true);
nCount = osr.docsReturned;
nCount2 = osr.resultElements.Length;
nCount3 = osr.estimatedHitCount;nCount and nCount2 are both 200.
nCount3 is 1332
Ok, no problem. Even though I asked for 1000 results, I figure it will only return 200 at a time, so I write a simple loop.
while (nTotalResults < nCount3)
osr = oses.doOracleSimpleSearch(strSearch, nTotalResults + 1, 200, false, false, true);
nCount = osr.docsReturned;
nTotalResults += nCount;
}After executing the search the first time, nTotalResults is set to 200, so I'm now requesting that the search starts at index 201 and to return the next block of 200.
osr.docsReturned is now = 0
stuck in infinite loop because it's not returning all my results.
Update:
It seems this is not just an API issue. If I do the search through the web interface, and go to page 20 (it's displaying 10 results per page) I see results. But as soon as I go to page 21, the page is blank even though it says there are over 1000 results.
Edited by: JimG on Feb 15, 2012 5:17 PMYou need to change the "Maximum Number of Results" from the Admin GUI.
Go to Global Settings -> Query Configuration, and you'll find it there. -
Trying to fetch a value in a java function and returning the array.
hello....I am trying to fetch a value in a java function and returning a array......I already write the pl/sql function which is working fine....but i think i m lost......when i run it through the jsp it shows me error........pls help
java code:=
public String [] viewx(String bid) throws SQLException, Exception {
String [] values;
try {
CallableStatement cstmt = null;
String SQL = "{?=call vi_dis.v_dis(?)}";
cstmt = con.prepareCall(SQL);
cstmt.registerOutParameter(1,Types.ARRAY);
cstmt.setString(2, bid);
cstmt.execute();
Array simpleArray = cstmt.getArray(1);
values = (String [])simpleArray.getArray();
cstmt.close();
} catch (SQLException sqle) {
error = "SQLException: Could not execute the query.";
throw new SQLException(error);
} catch (Exception e) {
error = "An exception occured while retrieving emp.";
throw new Exception(error);
return values;
pl/sql function
create or replace package vi_dis
as
function v_dis(vbid IN student.bid%type) return stuarray ;
end;
create or replace
package body vi_dis
as
function v_dis(vbid IN student.bid%type) return stuarray
is
l_stu stUarray :=stuarray();
cursor c_sel
is
SELECT CNAME
FROM COURSE C,ENROLL E
WHERE C.CID=E.CID
AND E.BID=vbid;
BEGIN
OPEN c_sel;
FETCH c_sel BULK COLLECT INTO l_stu;
l_stu.extend;
CLOSE c_sel;
RETURN l_stu;
EXCEPTION
WHEN NO_DATA_FOUND
THEN DBMS_OUTPUT.PUT_LINE('NO RESULT AVAILABLE');
CLOSE c_sel;
END;
END;
/BalusC wrote:
It is comparing the selected value against the List<SelectItem> returned by getSetoresOrigem() as it is during the apply request values phase of the form submit request.Ok. That's what I supposed JSF was doing.
BalusC wrote:
If the selected value isn't in there, then you will get this error.I can understand this, but is this right? As I said, the old value isn't really there because I changed the list values to new ones. But the new value (the value of fSetorOrigem ) corresponds to a value that exist in the new list items, so a valid value. So JSF is not considering that I also changed the list, not just the value. It is comparing the new value with the old list, not the new one. Acting like this JSF is making the page looks like a static HTML page, not a dynamic one. If I can't change the list and the value, what's the point of that? In my point of view I'm not doing anything wrong, I'm not violating any JSF rules.
Marcos -
Why does niDMM Fetch Multipoint Return Random Array of Results?
Alright so I am using the following example https://decibel.ni.com/content/docs/DOC-25292. The goal is to get a constant resistance reading from 10 channels. I have all the resistance readings coming in correctly. But, I noticed that everytime I analyze the array of the resistance data, there is no consistency where the channels data is stored. For example, channel 0 is tied to a 100 ohm resistor and all other 9 channels are tied to 220 ohm resistors. I will see the 100 ohm reading in the 0th element of the array but when the fetch gets called again the 100 ohm is now in the 5 element of the array. It seems random and uncontrollable, thoughts?
Inside of the While loop is a niDMM Read Status VI. That VI reads how many samples are in the backlog (number of samples already acquired).
Here's what I am suggesting you do
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
Acquire Data.PNG 11 KB -
Hi Experts,
I have on stored procedure which returns mote than one resultset i want that to store in two different temp table how can achieve this in SQL server.
following is the stored procedure and table that i need to create.
create procedure GetData as begin select * from Empselect * from Deptend
create table #tmp1 (Ddeptid int, deptname varchar(500),Location varchar(100))
Insert into #tmp1 (Ddeptid , deptname ,Location )
exec GetData
create table #tmp (empid int , ename varchar(500),DeptId int , salary int)
Insert into #tmp (empId,ename,deptId,salary)
exec GetData
Niraj SevalkarYou cant get two resultsets out of SP like this. The workaround is to merge and bring the resultsets.
For this number of columns as well as corresponding datatypes have to be compatible. Also you will need one additional column which indicates resultset value. Then use this as filter to get your desired resultset out
create procedure GetData as
begin
select 'resultset1' as Cat,*,.. N columns from Emp
union all
select 'resultset2' as Cat,*,.. N columns from Dept
end
create table #tmp1 (Ddeptid int, deptname varchar(500),Location varchar(100))
Insert into #tmp1 (Ddeptid , deptname ,Location )
Select column1,column2,column3
from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
Integrated Security=SSPI','Execute yourdb..GetData')
WHERE Cat = 'resultset1'
create table #tmp (empid int , ename varchar(500),DeptId int , salary int)
Insert into #tmp (empId,ename,deptId,salary)
Select column1,column2,column3, column4
from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
Integrated Security=SSPI','Execute yourdb..GetData')
WHERE Cat = 'resultset2'
also see
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx
Another method is to populate table with relevant resultset within procedure itself and then select from the table directly outside.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
C++ do not support JNi && how to return the array from jni?
hi,
1.. I have created the Cpp file to implemement the native method but it seems that the native method can not complie rightly , it tells me follows
error C2819: type 'JNIEnv_' does not have an overloaded member 'operator ->'
c:\program files\microsoft visual studio\vc98\include\jni.h(764) : see declaration of 'JNIEnv_'
c:\users\wangyue\desktop\java_gui\beattrack 5.6 - ������_������_������������ 5.7\beattrack.cpp(202) : error C2227: left of '->GetByteArrayRegion' must point to class/struct/union
then I use the c file to paste the same code, it can complie rightly , why? I really need my native method to complie rightly in Cpp file, how to solve it?
2.I want to return a double, for the most simple way, I do the following
#include "RealBeatTrack_BeatTrack.h"
JNIEXPORT jdoubleArray JNICALL Java_playaudio_BeatTrack_BeatTrack
(JNIEnv *env, jobject j, jbyteArray data)
jdouble outdata[4]={1,2,3,4};
return (*env)->NewDoubleArray(env, outdata);
then in the java code, I difine a array to receive it,
say double mydata[] = new double[4];
mydata= BeatTrack(buffedata);
but the java comlier tells me the Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space?
anyone can help me?
Thanksthanks for your reply
another problem of my!
the jni pass the string, I then convert it to the
const char* filename = env->GetStringUTFChars(fname,NULL);
then I use the filename to opent the file but fails, what is the problem???
FILE *fp= fopen(filename,"w"); // there are some problem here!!!
fprintf(fp, "%s\n","wangyue fighting!");
the error is as follows
# An unexpected error has been detected by Java Runtime Environment:
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0bfc1a55, pid=7040, tid=11384
# Java VM: Java HotSpot(TM) Client VM (10.0-b19 mixed mode windows-x86)
# Problematic frame:
# C [beattrack.dll+0x1a55]
# An error report file with more information is saved as:
# D:\programs\playAudio\hs_err_pid7040.log
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
# -
Is it possible to filter the nested table result set of table column
Hi
Create or replace type address_record
as object
( address_no number,
address_name varchar2,
address_startDate date,
address_expiryDate date
create or replace type address_rec_tab
as table of address_record;
Create table employee
(emp_no number,
emp_name varchar2,
adresses address_rec_tab
1st approach
==========
<pre>
select
emp.emp_no,
emp.emp_name,
emp.addresses
from employee emp,
table(*emp.addresses*) add
where add.address_expiryDate >=sysdate
</pre>
In the above example my SQL query address collection object is not returning filtered or current address list.
I suppose this is due to fact taht my where clause is not attached to the nested table.
Through my reading I gather that I can only use the following query to filter the address collection.
2nd approach
==========
<pre>
select
emp.emp_no,
emp.emp_name
cursor(select address_no,
address_name,
address_startDate,
address_expiryDate
from employee emp,
table (*emp.addresses*) add
where add.address_expiry_date >=sysdate)
from employee emp,
table (*emp.addresses*) add
where add.address_expiry_date >=sysdate) -- probably this redundent
</pre>
But this approch forces me to rebuild addresses collection object.
I was wondering anybody can suggest me a way so that 1st approach works? I do not have to rebuild collection object in this way.
Thanks for your help in advance
Regards
CharanCreate statements have been slightly modified;
Create or replace type address_record as object
( address_no number,
address_name varchar2(20),
address_startDate date,
address_expiryDate date
create or replace type address_rec_tab as table of address_record;
Create table employee
(emp_no number,
emp_name varchar2(20),
add_list address_rec_tab
nested table add_list store as a_list
insert into employee values (1, 'KMCHARAN', address_rec_tab ( address_record(1, 'NORTH POLE', trunc(sysdate-1), trunc(sysdate+10) ) ,
address_record(1, 'SOUTH_POLE', trunc(sysdate-1), trunc(sysdate+10) )
insert into employee values (2, 'ME', address_rec_tab ( address_record(2, 'EAST', trunc(sysdate-2), trunc(sysdate+12) ) ,
address_record(2, 'WEST', trunc(sysdate-2), trunc(sysdate+12) )
SQL> l
1 select *
2 from employee
3 ,table(add_list) a
4* where a.Address_StartDate = trunc(sysdate-1)
SQL> /
EMP_NO EMP_NAME
ADD_LIST(ADDRESS_NO, ADDRESS_NAME, ADDRESS_STARTDATE, ADDRESS_EXPIRYDATE)
ADDRESS_NO ADDRESS_NAME ADDRESS_S ADDRESS_E
1 KMCHARAN
ADDRESS_REC_TAB(ADDRESS_RECORD(1, 'NORTH POLE', '08-APR-10', '19-APR-10'), ADDRESS_RECORD(1, 'SOUTH_
1 NORTH POLE 08-APR-10 19-APR-10
1 KMCHARAN
ADDRESS_REC_TAB(ADDRESS_RECORD(1, 'NORTH POLE', '08-APR-10', '19-APR-10'), ADDRESS_RECORD(1, 'SOUTH_
1 SOUTH_POLE 08-APR-10 19-APR-10 -
Can I pass parameters to a subquery to return a narrow result set?
Hi-
HERE'S WHAT I'M TRYING TO DO:
Create a worksheet to aggregate the data that's returned from a subquery result set based on the user's specified date ranges.
HERE'S MY PROBLEM:
Discoverer is aggregating the data FOR EACH PARTICULAR DATE that shows up (ie-6/1, 6/2, 6/3) instead of across the entire specified date range (ie- 6/1-6/3) because the date parameters can only be applied to the main query instead of the subquery.
In essence, I need to:
SELECT location1, task1, sum(product1), max(product2)
FROM
(SELECT * FROM table1 WHERE date1 >= userSpecifiedDate1 and date1 <= userSpecifiedDate2)
GROUP BY location1, task1
...but using Discoverer's "Parameters" and "Totals" tool, so far I can only get Discoverer to do this :
SELECT location1, task1, sum(product1), max(product2), sum(product3)
FROM
(SELECT * FROM table1)
WHERE date >= userSpecifiedDate1 and date <= userSpecifiedDate2
GROUP BY location1, task1
Is there any way to apply date parameters to the subquery first so I'm aggregating across the range and not on each date?
Hope this makes sense. Any suggestions would be appreciated!Hi,
Yes.
You can pass parameter from search criteria to procedure.
First u need write a method in the AmImpl java class to call the procedure.
Like
public void callingProcWithinParams(String sreachCriterParam)
//pass the parameter to proc
Then shuttle this method to client interface. -
here am sending with my code which i comile gets resultset is closed exception.am using this for my jsp page.
team1Players gives the playerId of 11 players, and using this i wants to get the eir names from the second query,ie team1PlayerName.when i compile this the second query is executed and the message shows result set is closed,am not closing the result set any where.
pls help
package com.cricinfo.manager;
import com.cricinfo.bizobj.*;
import com.cricinfo.statuscodes.*;
import java.sql.*;
import java.util.HashMap;
public class reporterMatchDetails
public void reporterMatchDetails(){
public HashMap matchDetails(Connection con,String matchId)
HashMap <String,Object> responseMap=new HashMap <String,Object>();
try
Statement st=con.createStatement();
String teamPlayerQuery="SELECT * from CRICINFOMATCHPLAYERTABLE where matchId='"+matchId+"'";
ResultSet teamPlayerSet=st.executeQuery(teamPlayerQuery);
if (teamPlayerSet.next())
String team1Players=teamPlayerSet.getString("team1PlayerId");
System.out.println("team1 playerId is "+team1Players);
String team1PlayerQuery="SELECT * FROM CRICINFOPLAYERTABLE WHERE playerId in ("+team1Players+")";
System.out.println(team1PlayerQuery);
ResultSet team1PlayerSet=st.executeQuery(team1PlayerQuery);
while (team1PlayerSet.next())
String team1PlayerId=team1PlayerSet.getString("playerId");
String team1PlayerName=teamPlayerSet.getString("playerName");
System.out.println("team1 playerId is "+team1PlayerId);
System.out.println("team1 PlayerName is "+team1PlayerName);
catch (Exception e)
e.printStackTrace();
return responseMap;
}well i completely agree with what the previous poster has said...
you need to associcate the second resultset to a different statement altogether in this senario.
package com.cricinfo.manager;
import com.cricinfo.bizobj.*;
import com.cricinfo.statuscodes.*;
import java.sql.*;
import java.util.HashMap;
public class reporterMatchDetails{
public void reporterMatchDetails(){
public HashMap matchDetails(Connection con,String matchId){
HashMap <String,Object> responseMap=new HashMap <String,Object>();
try{
Statement st = con.createStatement();
Statement st1 = con.createStatement();
String teamPlayerQuery="SELECT * from CRICINFOMATCHPLAYERTABLE where matchId='"+matchId+"'";
String team1PlayerQuery="SELECT * FROM CRICINFOPLAYERTABLE WHERE playerId in ("+team1Players+")";
ResultSet teamPlayerSet = st.executeQuery(teamPlayerQuery);
if (teamPlayerSet.next()){
String team1Players=teamPlayerSet.getString("team1PlayerId");
System.out.println("team1 playerId is "+team1Players);
System.out.println(team1PlayerQuery);
ResultSet team1PlayerSet=st1.executeQuery(team1PlayerQuery);
while (team1PlayerSet.next()){
String team1PlayerId=team1PlayerSet.getString("playerId");
String team1PlayerName=teamPlayerSet.getString("playerName");
System.out.println("team1 playerId is "+team1PlayerId);
System.out.println("team1 PlayerName is "+team1PlayerName);
catch (Exception e){
e.printStackTrace();
return responseMap;
} check the above code.
hope that might help :)
REGARDS,
RaHuL -
Recursion: powerset , returning an array list of subsets
Hi, i've checked hundreds of webpages, but i still can;t figure out how to create a recursive method that returns the powersets of a set.
The sets returned are of type Arraylists
ex: set {1, 2, 3} returns an arrayList of arrayLists: { { }, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3} }.
The code should look somewhat like that: but the recursive call does not work...
ArrayList powerSet(ArrayList s) {
ArrayList result = new ArrayList();
if (s.size() == 1) { // base case
// return a new ArrayList containing just s
ArrayList tempAL = new ArrayList();
tempAL.add(s);
result.add(tempAL);
return result;
else {
Integer last = (Integer)s.get(s.size()-1); // separate the first character from the rest
ArrayList rest = new ArrayList(); // remainder of the set
rest.addAll(s);
rest.remove(rest.size()-1); // get rid off element "last"
// recursively call method on the remainder of the set
ArrayList L = new ArrayList();
L.add( powerSet(rest) ); // recursively call method on the remainder of the set
// return the set composed of the Union of
// the powerset of the set without the element (from the recursive call)
result.addAll(L);
// return the same set but
// with each element therein unioned with the element initially taken out
for(int i=0; i< L.size(); i++) {
ArrayList tmp = new ArrayList();
tmp.addAll( (ArrayList)L.get(i) );
tmp.add(last); // adding the element initially taken out
result.add(tmp);
return result;
Please someone help me. I know there has to be many errors during recursion. it's like i can't grasp the concept.
Thx a lot :)
Edited by: jonaphin on Oct 18, 2007 12:01 AM
btw, the output is: arraylists of arraylists of arraylists, depending on the depth of the recursion. argh :(
[[[[[[1]]], [[[1]], 2]], [[[[1]]], [[[1]], 2], 3]], [[[[[1]]], [[[1]], 2]], [[[[1]]], [[[1]], 2], 3], 4]]I think he changed
if (s.size() == 1) { // base case
to
if (s.size() == 0) { // base case
Also, jonaphin are you in Alexander Pelin's Data Structure Class at FIU? Because, amazingly enough... this is the exact assignment that has to get handed in today! (October 18) lol ;) -
Use boolean array to perform set operations
I am currently taking a computer science class that uses Java as the language of choice. I have no prior experience with Java. We have a homework assignment in which we are supposed to use a boolean array to implement set operations. We have to create a method that inserts an integer into the array, another that deletes an integer element, and several others. I am confused as how to do this with integers, as it is a boolean array. The datr for this class is:
private boolean base[];The constructor is:
public largeset(int size){ }We then have to create a method that inserts an integer into the array:
public void insert(int i){ }And one that deletes the element:
public void delete(int i) { }I am unsure how to do this using a boolean array. If it were an integer array I would not have any trouble, but I get an error when trying to insert/delete an integer from the boolean array. Can anyone help point me in the right direction? I would prefer advice only, not the actual code, as this is a homework assignment, and I would like to create the code myself so I actually know what I am doing. Thanks.This is the assignment exactly as posted on the course website:
In this homework, we will use a boolean array to implement various set operations. Please create a class called largeset that supports set operations of any number of elements. The data of this class is
private boolean[] base;The constructor of the class is
public largeset(int size); // create a boolean array of size "size" and store it in "base"The methods of the class are:
public void insert(int i); // insert number i into the current set, where 0 <= i < base.length
public void delete(int i); // delete number i from the current set, where 0 <= i < base.length
public boolean member(int i); // test if i is in the set
public largeset union(largeset B); // return the union of two sets
public largeset interset(largeset B); // return the intersection of two sets
public largeset subtract(largeset B); // return the subtraction of two sets
public largeset complement(); // return the complement of the current set
public boolean subset(largeset B); // test if the current set is a subset of set B
public int cardinality(); // return the number of elements in the current set
public String toString(); // return a string which is a printing of the current setThen create another class called testset that uses the largeset class. At first, please create the following two sets:
X = { 1, 3, 5, 7, ..., 999 };
Y = { 9, 18, 27, 36, ..., 999 };
Please perform the following tests:
1. display the cardinalities of X and Y, respectively.
2. display the content of substraction of Y by X.
3. display the square root of the sum of all the elements of X (Math.sqrt(x) will return the square root of x in double type).
4. For every pair of distinct elements x and y in Y, compute the sum of (Math.max(x, y) - Math.min(x, y)) (or equivalently, Math.abs(x - y)), and report this sum. -
Stored Procedure in Universe - Multi-result set
I have been trying to get more information on stored procedures as a source for universes. Business Objects designer 3.1 documentation says the following
Stored procedures with multi-result set
Example: A stored procedure that returns more than one result set. At design
time, several tables are created in the universe structure based on the same
stored procedure.
Does this mean?
1. These result sets are shown as multiple tables in designer?
2. if so, can these result sets be used as regular tables in designer to build joins and contexts.
I searched the forum for relevant threads before posting but could not find any. I tried posting this thread earlier - internet connection timed out. Please forgive me if this is a duplicate post.
ThanksDROP TABLE #DescendantsMS SQL Server - right?
Then don't drop the table.
From the MS docs for "create table"
Local temporary tables are visible only in the current session;
A local temporary table created in a stored procedure is dropped automatically when the stored procedure completes. The table can be referenced by any nested stored procedures executed by the stored procedure that created the table. The table cannot be referenced by the process which called the stored procedure that created the table. -
[PWS0007] Operation result set not found.
Hi,
I am working with java,db2 on AS/400.
When I am using my application with multiple users hitting the submit at the same time,I am getting
the following error:
Exception: [PWS0007] Operation result set not found. Cause . . . . . : The handle specified for the operation result set to be filled, returned, or used as the based on result set is not found for the server.
Recovery . . . : Correct the operation result set handle and do the function again.
Can anybody please tell me what could be the problem?
Thanks in advance.problem could be
1)Resulsets objects are not closing after getting data (like end of rRrsultSet while loop)
2)it is better close statements and connection objects also. -
Hello,
I try to get the client side result set cache working, but i have no luck :-(
I'm using Oracle Enterprise Edition 11.2.0.1.0 and as client diver 11.2.0.2.0.
Executing the query select /*+ result_cache*/ * from p_item via sql plus or toad will generate an nice execution plan with an RESULT CACHE node and the v$result_cache_objects contains some rows.
After I've check the server side cache works. I want to cache the client side
My simple Java Application looks like
private static final String ID = UUID.randomUUID().toString();
private static final String JDBC_URL = "jdbc:oracle:oci:@server:1521:ORCL";
private static final String USER = "user";
private static final String PASSWORD = "password";
public static void main(String[] args) throws SQLException {
OracleDataSource ds = new OracleDataSource();
ds.setImplicitCachingEnabled(true);
ds.setURL( JDBC_URL );
ds.setUser( USER );
ds.setPassword( PASSWORD );
String sql = "select /*+ result_cache */ /* " + ID + " */ * from p_item d " +
"where d.i_size = :1";
for( int i=0; i<100; i++ ) {
OracleConnection connection = (OracleConnection) ds.getConnection();
connection.setImplicitCachingEnabled(true);
connection.setStatementCacheSize(10);
OraclePreparedStatement stmt = (OraclePreparedStatement) connection.prepareStatement( sql );
stmt.setLong( 1, 176 );
ResultSet rs = stmt.executeQuery();
int count = 0;
for(; rs.next(); count++ );
rs.close();
stmt.close();
System.out.println( "Execution: " + getExecutions(connection) + " Fetched: " + count );
connection.close();
private static int getExecutions( Connection connection ) throws SQLException {
String sql = "select executions from v$sqlarea where sql_text like ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, "%" + ID + "%" );
ResultSet rs = stmt.executeQuery();
if( rs.next() == false )
return 0;
int result = rs.getInt(1);
if( rs.next() )
throw new IllegalArgumentException("not unique");
rs.close();
stmt.close();
return result;
100 times the same query is executed and the statement exection count is incemented every time. I expect just 1 statement execution ( client database roundtrip ) and 99 hits in client result set cache. The view CLIENT_RESULT_CACHE_STATS$ is empty :-(
I'm using the oracle documentation at http://download.oracle.com/docs/cd/E14072_01/java.112/e10589/instclnt.htm#BABEDHFF and I don't kown why it does't work :-(
I'm thankful for every tip,
André KullmannI wanted to post a follow-up to (hopefully) clear up a point of potential confusion. That is, with the OCI Client Result Cache, the results are indeed cached on the client in memory managed by OCI.
As I mentioned in my previous reply, I am not a JDBC (or Java) expert so there is likely a great deal of improvement that can be made to my little test program. However, it is not intended to be exemplary, didactic code - rather, it's hopefully just enough to illustrate that the caching happens on the client (when things are configured correctly, etc).
My environment for this exercise is Windows 7 64-bit, Java SE 1.6.0_27 32-bit, Oracle Instant Client 11.2.0.2 32-bit, and Oracle Database 11.2.0.2 64-bit.
Apologies if this is a messy post, but I wanted to make it as close to copy/paste/verify as possible.
Here's the test code I used:
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleDataSource;
import oracle.jdbc.OracleConnection;
class OCIResultCache
public static void main(String args []) throws SQLException
OracleDataSource ods = null;
OracleConnection conn = null;
PreparedStatement stmt = null;
ResultSet rset = null;
String sql1 = "select /*+ no_result_cache */ first_name, last_name " +
"from hr.employees";
String sql2 = "select /*+ result_cache */ first_name, last_name " +
"from hr.employees";
int fetchSize = 128;
long start, end;
try
ods = new OracleDataSource();
ods.setURL("jdbc:oracle:oci:@liverpool:1521:V112");
ods.setUser("orademo");
ods.setPassword("orademo");
conn = (OracleConnection) ods.getConnection();
conn.setImplicitCachingEnabled(true);
conn.setStatementCacheSize(20);
stmt = conn.prepareStatement(sql1);
stmt.setFetchSize(fetchSize);
start = System.currentTimeMillis();
for (int i=0; i < 10000; i++)
rset = stmt.executeQuery();
while (rset.next())
if (rset != null) rset.close();
end = System.currentTimeMillis();
if (stmt != null) stmt.close();
System.out.println();
System.out.println("Execution time [sql1] = " + (end-start) + " ms.");
stmt = conn.prepareStatement(sql2);
stmt.setFetchSize(fetchSize);
start = System.currentTimeMillis();
for (int i=0; i < 10000; i++)
rset = stmt.executeQuery();
while (rset.next())
if (rset != null) rset.close();
end = System.currentTimeMillis();
if (stmt != null) stmt.close();
System.out.println();
System.out.println("Execution time [sql2] = " + (end-start) + " ms.");
System.out.println();
System.out.print("Enter to continue...");
System.console().readLine();
finally
if (rset != null) rset.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
}In order to show that the results are cached on the client and thus server round-trips are avoided, I generated a 10046 level 12 trace from the database for this session. This was done using the following database logon trigger:
create or replace trigger logon_trigger
after logon on database
begin
if (user = 'ORADEMO') then
execute immediate
'alter session set events ''10046 trace name context forever, level 12''';
end if;
end;
/With that in place I then did some environmental setup and executed the test:
C:\Projects\Test\Java\OCIResultCache>set ORACLE_HOME=C:\Oracle\instantclient_11_2
C:\Projects\Test\Java\OCIResultCache>set CLASSPATH=.;%ORACLE_HOME%\ojdbc6.jar
C:\Projects\Test\Java\OCIResultCache>set PATH=%ORACLE_HOME%\;%PATH%
C:\Projects\Test\Java\OCIResultCache>java OCIResultCache
Execution time [sql1] = 1654 ms.
Execution time [sql2] = 686 ms.
Enter to continue...This is all on my laptop, so results are not stellar in terms of performance; however, you can see that the portion of the test that uses the OCI client result cache did execute in approximately half of the time as the non-cached portion.
But, the more compelling data is in the resulting trace file which I ran through the tkprof utility to make it nicely formatted and summarized:
SQL ID: cqx6mdvs7mqud Plan Hash: 2228653197
select /*+ no_result_cache */ first_name, last_name
from
hr.employees
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 10000 0.10 0.10 0 0 0 0
Fetch 10001 0.49 0.54 0 10001 0 1070000
total 20002 0.60 0.65 0 10001 0 1070000
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 94
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
107 107 107 INDEX FULL SCAN EMP_NAME_IX (cr=2 pr=0 pw=0 time=21 us cost=1 size=1605 card=107)(object id 75241)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 10001 0.00 0.00
SQL*Net message from client 10001 0.00 1.10
SQL ID: frzmxy93n71ss Plan Hash: 2228653197
select /*+ result_cache */ first_name, last_name
from
hr.employees
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.01 0 11 22 0
Fetch 2 0.00 0.00 0 0 0 107
total 4 0.00 0.01 0 11 22 107
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 94
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
107 107 107 RESULT CACHE 0rdkpjr5p74cf0n0cs95ntguh7 (cr=0 pr=0 pw=0 time=12 us)
0 0 0 INDEX FULL SCAN EMP_NAME_IX (cr=0 pr=0 pw=0 time=0 us cost=1 size=1605 card=107)(object id 75241)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 2 0.00 0.00
log file sync 1 0.00 0.00
SQL*Net message from client 2 1.13 1.13The key differences here are the execute, fetch, and SQL*Net message values. Using the client-side cache, the values drop dramatically due to getting the results from client memory rather than round-trips to the server.
Of course, corrections, clarifications, etc. welcome and so on...
Regards,
Mark -
WAD : Result set is too large; data retrieval restricted by configuration
Hi All,
When trying to execute the web template by giving less restiction we are getting the below error :
Result set is too large; data retrieval restricted by configuration
Result set too large (758992 cells); data retrieval restricted by configuration (maximum = 500000 cells)
But when we try to increase the number of restictions it is giving output. For example if we give fiscal period, company code ann Brand we are able to get output. But if we give fical period alone it it throwing the above error.
Note : We are in SP18.
Whether do we need to change some setting in configuration? If we yes where do we need to change or what else we need to do to remove this error
Regards
KarthikHi Karthik,
the standard setting for web templates is to display a maximum amount of 50.000 cells. The less you restrict your query the more data will be displayed in the report. If you want to display more than 50.000 cells the template will not be executed correctly.
In general it is advisable to restrict the query as much as possible. The more data you display the worse your performance will be. If you have to display more data and you execute the query from query designer or if you use the standard template you can individually set the maximum amount of cells. This is described over [here|Re: Bex Web 7.0 cells overflow].
However I do not know if (and how) you can set the maximum amount of cells differently as a default setting for your template. This should be possible somehow I think, if you find a solution for this please let us know.
Brgds,
Marcel
Maybe you are looking for
-
Editing text in Acrobat Pro doc using Reader
I've created documents in Acrobat 8 Pro for a client who needs to be able to add a few lines of text in Reader, then re-save and email the PDFs. Each time they try, though, they get the message telling them that they can't save the PDF and should pri
-
How to enabled "Preview Template" and/or "Delete Template"
Hello All, I am trying to preview a standard XML Template but it is greyed out. When i take my mouse over it.. It says "Preview Template Disabled". It says "Delete Template disabled" when i move my mouse over Delete.. How do i enable these features s
-
HT201205 iPhone 5 is stuck in searching mode. Will not recognize bluetooth device.
How do I get my iPhone 5 to recognize my Jabar bluetooth? It just gets stuck in searching mode.
-
Hi, I have download oracle 11g for linux. We have one to create a new database for one of our production system. Shall I create the database on 11g or wait for some time.(we have tested the application on 10g) Regards MMU
-
Ipad3 takes ages to load new emails
Hi, I have an iPad 3 and an IPhone 4, and since last week they both take ages to download any new emails, 5 to 7 minutes to open an email. I went on my PC and it works fine, it's only on my apple products, tried warm reboot, connecting to iTunes etc,