Getting the record count from result set
i'm retreiving the result set using the executeQuery method, now i want to know how many records are there in the result set, that is the record count of the result set.
one solution to that is to first use the executeUpdate and then use the executeQuery but i think that is not the right way.
so please tell me is there any method in jdbc to get that thing done
Tanx
Hi
Do you know if your DB supports "insensitive scrolling"?
SQL generally do, but some don't - I had the same problem with the
open source version of Interbase from Phoenix...
Anyway - try creating your statement this way:
public Statement createStatement(int resultSetType, int resultSetConcurrency)
throws SQLException
...where resultset type should be:
ResultSet.TYPE_SCROLL_INSENSITIVE
Then you can do this:
ResultSet rs = stm.executeQuery(q);
int size = rs.last(); //this what you looking for?
rs.beforeFirst();
while(rs.next()){
}
Similar Messages
-
Get the record count from a query
Hi,
does anyone know how to get the record count from a sql query?
e.g: I've got a ResultSet from the Statement.excuteQuery(), and I want to know how many records this ResultSet contains, how to get this?
I'd read thoughout the documents of Statement and ResultSet, but couldn't find a solution, do I have to use another seperate query such as "select count(*)" to do this?
thanks.
Yang LiuIf you are not using a scrollable result set then the following is the best way to do it.
there are several key words in SQL that can be used, the one you are interested in is count();
so if your query at the moment is
"select col1, col2, col3 from my_table where col2=? and col3=?"you can work out how many rows will be returned by executing this command first
"select count(col1) from my_table where col2=? and col3=?"this will return a result set with one row and one column, you can get the row count as follows:
ResultSet rs = ps.executeQuery();
int rowCount = rs.getInt(1);I hope this helps :) -
How to get the record count printed for the report in the Dashboards
Hi,
I would like to get the record count printed at the bottom of every dashboard report like:
< 1 - 25 of 6300 > instead of < 1 - 25 >
Any help is appreciated
Regards
BI have tried the following formula which identifies the lowest grain but it does not seem to give me correct result.. I am not getting the correct count. I am getting as 3.A work order can be updated only once at one point of time.hence the formula
MAX(RCOUNT(CAST("SR Wo Fact"."Crm Wo Number" AS CHAR) ||CAST("SR Wo Fact"."PSC Timestamp" as char)))
I tried only MAX(RCOUNT(1)), but I was able to get the record count as corect for Administrator but not for other users.
Has anyone come across this scenario.
Thanks Shravan
Edited by: 786443 on Aug 19, 2010 10:22 AM -
File Adapter - how to get the file count from a folder
Hi All,
I have a requirement that have to poll a directory when the file count is reached to number N (ex:number of files avilable in folder is 5) otherwise it should wait and not pick any of the files. Is it possible to get the file count from a folder using file adapter ?? otherwise please suggest me an approach to achieve this requirement.
Thanks,
JJHi Sarath,
Thank you for your reply.
Go with the list files operation of file adapter it will gives you the number of files in the specified folder as you given. . - this step is already done.
When the number of files reaches your count startup your webservice that which can polls the files. . . - how can i acheive this?? Have to poll the directory and process the number files - please let me know, what could be added to the webservice which is being invoked after cheking file count from parent process.
The reason for the above question is - we cannot use ReadFile operation in second webservice because it will be automatically triggered when the file is avilable. Also SyncRead operation supports reading one file in b/w bpel process. Kindly explain me the implementation steps.
Thanks,
JJ -
How to get the FILE COUNT from File directory
Hello,
i have to develop a scenario like, get the file count from source file directory and validate whether the file count is 5 or not. if 5 files exist i need to process those 5 files to DB tables. if file count is not equal to 5 then i need to send a mail to customer that files are missed at source directory. (subject as files were missed at source directory and in content i need to display the file names exist at source file directory. So that missed file will be generated by the customer based on this mail).
Could you please let me know how to get the count of files from source file directory. if it is possible only with UDF please provide the Java code
Best Regards,
SARANDo these files have some fixed names?
Can you try to use the option Advanced Selection For Source File to make XI pick all 5 files in one shot?
Check this blog on the same -
/people/mickael.huchet/blog/2006/09/18/xipi-how-to-exclude-files-in-a-sender-file-adapter
If this is not a option - BPM sounds the only possible way.
Regards,
Bhavesh -
The Query below is part of a huge query. The snipet is just the part that I need to make a change.
For the query below, how can I get the recordcount in the select inside the case statement? I want to only output the r_text when the record count of the select is zero (0) else make the output to r_text null
select
distinct a.style_id, b.sty, b.season, a.cust, a.ad_d, b.code,
(case when b.code = 'MAKE' then
(select min(t.value) from sn.age r, sn.text t
where r.t_id = '18' and r.name = 'MTGNSL'
and r.t_id = t.t_id
and r.name = t.name and r.text_id = t.text_id
and r.id_1 = a.id
) end) r_text,
(case when b.code is null then 'Blank Code'
when b.code = 'MAKE' then 'MAKE' end) err
If you are not using a scrollable result set then the following is the best way to do it.
there are several key words in SQL that can be used, the one you are interested in is count();
so if your query at the moment is
"select col1, col2, col3 from my_table where col2=? and col3=?"you can work out how many rows will be returned by executing this command first
"select count(col1) from my_table where col2=? and col3=?"this will return a result set with one row and one column, you can get the row count as follows:
ResultSet rs = ps.executeQuery();
int rowCount = rs.getInt(1);I hope this helps :) -
Get the records number from internal table with conditon.
Internal table itab got more than 1000 records,now i need to get the number of records with condition that itab-field1 = 'XXXX'.
actully, i got an inefficient logic to count the number in a loop statement. is there better way to implement it?Hi,
One alternative solution, which may be useful for other parts of your program, is to have an aditional itab1 with a single column/field (field1), which acts like a index or shadow table, and which is filled simultaneously with itab. Then you can use DESCRIBE TABLE itab1 LINES lv_lines.
Atb -
How to get the record count before fetch
CREATE PACKAGE demo_cur_pkg AS
TYPE EmpName IS RECORD (name VARCHAR2(10));
TYPE cur_type IS REF CURSOR RETURN EmpName;
PROCEDURE open_emp_cur (
curs IN OUT cur_type,
dept_num IN NUMBER);
END;
CREATE PACKAGE BODY demo_cur_pkg AS
CREATE PROCEDURE open_emp_cur (
curs IN OUT cur_type,
dept_num IN NUMBER) IS
BEGIN
OPEN curs FOR
SELECT ename FROM emp
WHERE deptno = dept_num
ORDER BY ename ASC;
END;
END;
After this package has been stored, you can open the cursor curs by calling the open_emp_cur stored procedure from your Pro*C/C++ program, and FETCH from the cursor in the program. For example:
sql_cursor emp_cursor;
char emp_name[11];
EXEC SQL ALLOCATE :emp_cursor; /* allocate the cursor variable */
/* Open the cursor on the server side. */
EXEC SQL EXECUTE
begin
demo_cur_pkg.open_emp_cur(:emp_cursor, :dept_num);
end;
EXEC SQL WHENEVER NOT FOUND DO break;
for (;;)
EXEC SQL FETCH :emp_cursor INTO :emp_name;
printf("%s\n", emp_name);
Any solutioon is welcomeFail to understand why you want to introduce exception processing - e.g. use methodA for less than 10,000 rows and use methodB for 10,000 and more.
Why not use methodC - optimal support for fetching, irrespective of whether there are 1 row to fetch, or a 100,000 rows?
There is no best way for fetching a small number of rows versus a different best way for fetching more rows. There is a single optimal method - and this remains the same irrespective of the number of rows being returned. -
How to return the record count of a query to a number variable
How would I get the record count from a query without using a cursor to step through the query and count the records individually?
query: select * from table1 where column1 = column2
How would I get the record count of the query above?
thanks,
michelleI figured it out
select count(*) into theCount
from ( select * from table1 where column1=column2 );
thanks,
michelle -
Get the min value from a record set
RDBMS 9.2.0.6
What is the best (fast) way to get the min date
from a record set.
For example:
table tab (col1 NUMBER, col2 DATE ) with 47697857 records.
I would like to get the MIN(col2) where col1 = XXXXI would create an index on col1, col2. If you are only returning the date and possibly col1, then Oracle will not even need to look at the table, all the required data is in the index. Even if you want additional columns from the tble, Oracle should pick the index scan in most cases, unlessyou are looking for a significant fraction of the rows in the table.
HTH
John -
How to get the record set into array?
Hi,
I want to get the record set into array in the procedure and do the processing of the array later in procedure.
below is the stored procedure i am working on:
procedure bulk_delete_group(p_group_id in Array_GroupListID) as
begin
for i in p_group_id.first..p_group_id.last loop
--Here I have to get the list of user id before deleting group
SELECT user_id into *<SOME ARRAY>* FROM group_members WHERE group_id = p_group_id(i);
DELETE group WHERE group_id = p_group_id(i);
--Process the user id array after group deletion..
end loop;
end bulk_delete_group;
Thanks in advance
AdityaSomething like this ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.20
satyaki>
satyaki>
satyaki>select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
9999 SATYAKI SLS 7698 02-NOV-08 55000 3455 10
7777 SOURAV SLS 14-SEP-08 45000 3400 10
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 4450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 7000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
13 rows selected.
Elapsed: 00:00:02.37
satyaki>
satyaki>create type np is table of number;
2 /
Type created.
Elapsed: 00:00:03.32
satyaki>
satyaki>Create or Replace Procedure myProc(myArray np)
2 is
3 i number(10);
4 rec emp%rowtype;
5 Begin
6 for i in 1..myArray.count
7 loop
8 select *
9 into rec
10 from emp
11 where empno = myArray(i);
12
13 dbms_output.put_line('Employee No:'||rec.empno||' Name:'||rec.ename);
14 end loop;
15 End myProc;
16 /
Procedure created.
Elapsed: 00:00:00.88
satyaki>
satyaki>
satyaki>declare
2 v np:=np(9999,7777);
3 begin
4 myProc(v);
5 end;
6 /
Employee No:9999 Name:SATYAKI
Employee No:7777 Name:SOURAV
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.30
satyaki>Regards.
Satyaki De. -
How to get the time length from send record command to record video really?
I have two buttons. Record/Stop
I press Record button to record the video and press Stop
button to stop recording.Now,I spend 1986 ms from press Record
button to press Stop button.
But the flv file's length is 1920 or 1910 or 1915 ms.
So I want to get the time length from send record command to
record video really.
Can you give me some suggests.
Thanks!maybe you have lag in publishing.... are you try watch de
NetStream.liveDelay() method?
or start counting when NetStream.onStatus has
"NetStream.Record.Start" and "NetStream.Record.Stop" in information
objects.... -
How to get the Node Value from XmlValue result?
Hi ,
I am not able to get the Node Value from the result. In my XQuery im selecting till a Node, if i change my query as
collection('PhoneBook')/phone_book/contact_person/address/string()", qc);
im getting the node value, but here the problem is its not a Node so i cannot get the Node name.
So how can i get the Node Name and Node value together?
any help please ????
XML :
<?xml version="1.0" encoding="UTF-8"?>
<phone_book>
<contact_person>
<name>
<first_name>Michael</first_name>
<second_name>Harrison</second_name>
</name>
<address city="yyyyy" pincode="600017" state="xxxxx">
176 Ganesan street, Janakinagar, alwarthirunagar
</address>
</contact_person>
<phone_number type="mobile">9881952233</phone_number>
<phone_number type="home">044-24861311</phone_number>
<phone_number type="office">080-12651174</phone_number>
</phone_book>
Code:
XmlQueryContext qc = manager.createQueryContext();
XmlResults rs = manager.query
("collection('PhoneBook')/phone_book/contact_person/address", qc);
while(rs.hasNext()){
XmlValue val = rs.next();
System.out.println(val.getNodeName() + " = [ " + val.getNodeValue() + " ] ");
Output
address = [ ]You are right, this seemed un-intuitive to me too, but I finally understood how it's done.
The "value" of a node is actually the total amount of text that is not contained in any of the node's child nodes (if any). So a node with child nodes can still have text value.
To get the 'value' of an element node, you must therefore concatenate the values of all children of type "XmlValue::TEXT_NODE", of that node. Try it.
In your example, the <address> node has no child elements, my guess is that BDB XML stores the address string "176 Ganesan street, Janakinagar, alwarthirunagar" inside a child node of <address> node (of type XmlValue::TEXT_NODE) because you wrote the string on a separate line. -
How do I get a page count from the HP Photosmart 5514?
How do I get a page count from the HP Photosmart 5514?
Simple. Access the printer web gui by typing in the printers IP address into your browsers address bar. Select Tools/Usage reports. Done.
-
Getting every odd-numbered row from result set
select *
from mytable
where MOD(rownum,2) = 1;
Why does this not give me every odd-numbered row from result set? It returns just 1 row....
Thank uWhen you say MOD(ROWNUM,2)=1 it will list only the first row with rowid which is devisible by 2 and gives a reminder 1.
Just tweak your query with a GROUP BY:
SQL> select rownum from your_table group by rownum having mod(rownum,2) =1;
ROWNUM
1
3
5
7
9
11
13
15
17
19
21
ROWNUM
23
25
27
29
31
33
35
37
39
41
43
etc...
[pre]
Jithendra
Maybe you are looking for
-
Hello! I will kindly ask for your honest opinions as I want to study for an Oracle Linux exam and I need to get the below indicated topics covered, but unfortunately I could not find a book to cover them all (as I did for Oracle 11g). Please help me
-
Hello All, I am sending the output of a sales order as a PDF attachment via outlook mail. It wokrs fine. but only worry is the Chinese characters are appearing strange and not what we need. If I print / preview the output in SAP it shows the Chinese
-
XQuery Transformation in OSB for array of values
Hi, I have followed the below tuts on the OSB tutorial. http://www.oracle.com/technetwork/articles/jumpstart-for-osb-development-page--097357.html Everything works fine. Except for the "GetAllCustomer" branch node. Step1 : Configured the BusinessServ
-
Hardware Overview: Model Name: MacBook Model Identifier: MacBook5,1 Processor Name: Intel Core 2 Duo Processor Speed: 2 GHz Number Of Processors: 1 Total Number Of Cores: 2 L2 Cache: 3 MB Memory: 2 GB Bus Speed: 1.07 GHz Boot ROM Version: MB51.007D.B
-
Hello, I have 300 users that require several ( 45 different) share drives mapped to their computers. Problem is not all of them need all the shares. I was thinking about setting up a logon script to do it but, I wanted to check if there is any other