Result Set only returning one row...
When I run the following query in my program, I only get one row.
SELECT * FROM (SELECT * FROM ul_common_log_event WHERE application_name = 'Configuration' ORDER BY cle_id DESC) WHERE ROWNUM <= 500;
However when I run it in TOAD, I get all the rows I am looking for.
Here's my java
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
My record set only contain one row. I am using Oracle 9 OCI driver BTW.
Any ideas? Thanks!
Good thinking. That was the first thing I tried. That was not the problem. It turns out that I was stomping my rs object in another method. Problem resolved!
Thanks for the reply!
Similar Messages
-
How just return one row of a one to many join..
So I have a one to many join where the SMOPERATOR table has data I need however it has a couple of rows that match the JOIN condition in there. I just need to return one row. I think this can be accomplished with a subquery in the join however have not been able to come up with the right syntax to do so.
So:
SELECT "NUMBER" as danumber,
NAME,
SMINCREQ.ASSIGNMENT,
SMOPERATOR.PRIMARY_ASSIGNMENT_GROUP,
SMOPERATOR.WDMANAGERNAME,
SMINCREQ.owner_manager_name,
SMINCREQ.subcategory, TO_DATE('01-'||TO_CHAR(open_time,'MM-YYYY'),'DD-MM-YYYY')MONTHSORT,
(CASE WHEN bc_request='f' THEN 'IAIO'
WHEN (bc_request='t' and substr(assignment,1,3)<>'MTS') THEN 'RARO'
WHEN (bc_request='t' and substr(assignment,1,3)='MTS') THEN 'M'
ELSE 'U' end) as type
from SMINCREQ
left outer join SMOPERATOR on SMINCREQ.assignment=SMOPERATOR.primary_assignment_group
WHERE SMINCREQ.owner_manager_name=:P170_SELECTION and SMOPERATOR.wdmanagername=:P170_SELECTION
AND open_time BETWEEN to_date(:P170_SDATEB,'DD-MON-YYYY') AND to_date(:P170_EDATEB,'DD-MON-YYYY')
AND
(bc_request='f' and subcategory='ACTIVATION' and related_record<>'t')
OR
(bc_request='f' and subcategory<>'ACTIVATION')
OR
(bc_request='t' and substr(assignment,1,3)<>'MTS')
order by OPEN_TIMeHi,
This sounds like a Top-N Query , where you pick N items (N=1 in this case) off the top of an orderded list. I think you want a separate ordered list for each assignment; the analytic ROW_NUMBER function does that easily.
Since you didn't post CREATE TABLE and INSERT statements for your sample data, I'll use tables from the scott schema to show how this is done.
Say you have a query like this:
SELECT d.dname
, e.empno, e.ename, e.job, e.sal
FROM scott.dept d
JOIN scott.emp e ON d.deptno = e.deptno
ORDER BY dname
;which produces this output:
DNAME EMPNO ENAME JOB SAL
ACCOUNTING 7934 MILLER CLERK 1300
ACCOUNTING 7839 KING PRESIDENT 5000
ACCOUNTING 7782 CLARK MANAGER 2450
RESEARCH 7876 ADAMS CLERK 1100
RESEARCH 7902 FORD ANALYST 3000
RESEARCH 7566 JONES MANAGER 2975
RESEARCH 7369 SMITH CLERK 800
RESEARCH 7788 SCOTT ANALYST 3000
SALES 7521 WARD SALESMAN 1250
SALES 7844 TURNER SALESMAN 1500
SALES 7499 ALLEN SALESMAN 1600
SALES 7900 JAMES CLERK 950
SALES 7698 BLAKE MANAGER 2850
SALES 7654 MARTIN SALESMAN 1250Now say you want to change the query so that it only returns one row per department, like this:
DNAME EMPNO ENAME JOB SAL
ACCOUNTING 7782 CLARK MANAGER 2450
RESEARCH 7876 ADAMS CLERK 1100
SALES 7499 ALLEN SALESMAN 1600where the empno, ename, job and sal columns on each row of output are all taken from the same row of scott.emp, though it doesn't really matter which row that is.
One way to do it is to use the analytic ROW_NUMBER function to assign a sequence of unique numbers (1, 2, 3, ...) to all the rows in each department. Since each sequence startw with 1, and the numbers are unique within a department, there will be exactly one row per departement that was assigned the numebr 1, and we''ll display that row.
Here's how to code that:
WITH got_r_num AS
SELECT d.dname
, e.empno, e.ename, e.job, e.sal
, ROW_NUMBER () OVER ( PARTITION BY d.dname
ORDER BY e.ename
) AS r_num
FROM scott.dept d
JOIN scott.emp e ON d.deptno = e.deptno
SELECT dname
, empno, ename, job, sal
FROM got_r_num
WHERE r_num = 1
ORDER BY dname
;Notice that he sub-query got_r_num is almost the same as the original query; only it has one additional column, r_num, in the SELECT clause, and the sub-qeury does not have an ORDER BY clause. (Sub-queries almost never have an ORDER BY clause.)
The ROW_NUMBER function must have an ORDER BY clause. In this example, I used "ORDER BY ename", meaning that, within each department, the row with the first ename (in sort order) will get r_num=1. You can use any column, or expression, or expressions in the ORDER BY clause. You muight as well use something consistent and predictable, like ename, but if you really wanted arbitrary numbering you could use a constant in the analytic ORDER BY clause, e.g. "ORDER BY NULL". -
How do I set only the first row of a DataGrid as the selected row?
I have a "Go" button on a search form that fetches data into an already data bound grid. After the data is fetched, I want to make the first row in the Datagrid the selected row, as if the user clicked on it. If the result set is empty, I don't want the code to crash. (I only want one row to be able to be selected at a time)
protected function btnGo_clickHandler(event:MouseEvent):void
getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);
grdSBJs. // ????? What goes here to select the first row?This should do it.
If this post answered your question or helped, please mark it as such.
if(myDataGrid.dataProvider.length > 0){
myDataGrid.selectedIndex = 0; -
Edit Appraisals: Notes only shows one row at a time
Under the Employee Review tab of MSS-->Edit Appraisals, when I click to create an appraisal, the appraisal form in our system has areas to add notes. However, in the portal, the area to add notes is only 1 row. It is scrollable, but you can only see one row of text at a time. How can I expand the notes area/editor to show multiple lines of text?
Turns out the configuration is on the R/3 side when setting up the Appraisal. There is an option for number of lines for notes.
-
How come Java methods can only return one variable?
Hi,
I am just curious, how come C/C++/Java methods/functions can only return one argument but can accept many parameters.
I know that the workaround is to return an object, but sometimes creating a class is just too much overhead.
Thank you in advance.Hello,
It's an interesting discussion. To get the full answer to your question, you'd have to consult the library and find books on programming language design and implementation.
I believe the tradition goes all the way back to the first programming languages having subroutines/procedures/functions/methods in them: you can return nothing at all (void i Java) or a single value. The need for returning a single value, I guess, comes from the wish to embed calls in arithmetic expressions:
res = 2 * someObject.foo(x) - anotherObj.bar(a,b);To my knowledge, few languages allow you to return more values. One that does is BETA (see www.daimi.au.dk/~beta/). Though not indispensable, it's convenient sometimes. I don't know why it's not more widespread.
Yours,
Ole -
Jdbc:odbc bridge only returning one result when a count show 148 !
Hello,
Am sure i have done something stupid, but i have an issue with jdbc:odbc ....
It is a simple sceanrio that i have coded umpteen times before ...
I have the following ....
1. Connection to DB2 on an IBM i5 (I apologise for not using native drivers from jt400.jar, but i had an ODBC code example and was in a rush - no excuse i know)
2. Statement object created from connection above
3. A string with my SQL in it
4. A result set for the results.
These are created as follows:
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(ODBCSource, userID, password);
if (con == null) {
// error handling not relevant here
} else {
Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
String SQL = "select * from table";
ResultSet rs = s.executeQuery(SQL);
i then try to loop ....
while (rs.next() )
// stuff
however, i only ever get one result .... if i stick in the check for isLast, the first loop hits this check, i get my little status message, and the loop ends.
while (rs.next() )
if (rs.isLast() )
System.out.println("I am on last record");
BUT if i run the SQL
"select count(*) from table" ... i get a count of 148 !!
I tried setting the FetchSize through setFetchSize(), but made no difference.
This is running on a JBoss server 4.2.1GA, JDK is "jdk1.6.0_02" .... i have a suspicion that this may be a JBoss specfic issue, as this exact code runs just fine on the Domino platform that it was originally on, if this is the case, i apologise for wasting everyones time .... but would still appreciate any pointers you can give me.
Cheerssorry .... just relaised this is in the wrong forum ... reposted in the Database connectivity forum !!
-
Returning one row in a view(only)
Is there any function that I can use to return just one row from a query?
I tryed the old LIMIT TO from rdb, but its useless...
I´m using a Oracle8Try using "where ROWNUM = 1" for the first row returned by the select
-
64-bit driver only returns first row of table
I have a C++ application using ADO (the MSADO COM components) and the Oracle OLEDB provider for database access. The application works fine on a 32-bit computer using the 32-bit Oracle client and driver. However, when I run a 64-bit build of the application, running on a 64-bit computer (Windows Server 2008 x64), using the 64-bit Oracle client and driver, a SELECT operation returns only the first row of the table.
Note that this is only happening with the ActiveX ADO components. ADO.NET is not having a problem.
In both cases I am connecting to the same database, which is Oracle 10.2 (32-bit) running on a different server. I have tested with Oracle client 10.2.0.4 and 11.1.0.7 and got the same result in both cases.
I have reproduced the issue with a simple table (one column, NVARCHAR2(255)) and simple code.
In the code, I execute "select count(*) from tablename" and get the correct record count (more than one record). But when I then open the recordset ("select columnname from tablename"), ADO reports EndOfFile after I have read the first row and called MoveNext on the recordset.
My Oracle knowledge is limited so I don't know if there are driver properties I should be checking.
Anyone have ideas?
Thanks in advance.For 10.2 it's fixed in 10204 Patch 21 and higher.
For 11.1 it's fixed in 11107 Patch 12 and higher.
Cheers,
Greg -
SEARCH (only returns one record?)
When I run my search, it only returns the first record it finds. Can sombody give me a clue to why it won't return multipule records?
try{
//Connect to the Database
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:ComfortZoneDB");
Statement s = con.createStatement();
String sql = "SELECT * from Hydronics WHERE Keyword LIKE '%"+field+"%' order by Keyword";
//Contains results from the SQL Query
ResultSet rs = s.executeQuery(sql);
// Displays it all out in a table
while (rs.next()) {
txt_search1.setText(""+rs.getString(1)+ "|" rs.getString(2) "|"+rs.getString(3)+ "|"+rs.getString(4)+ "|"+rs.getString(5)+ "|"+rs.getString(6)+ "|"+rs.getString(7));
rs.close();
s.close();
con.close();
catch(SQLException e){
catch(Exception e){
}Sir,
Slappy presents Table Models 101.
import java.sql.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
public class SlappyReadOnlyTableModel{
private LinkedList rows;
private String[] colnames;
private int[] coltypes;
public SlappyReadOnlyTableModel(ResultSet rs)throws Exception{
ResultSetMetaData rsmd = rs.getMetaData();
colnames = new String[rsmd.getColumnCount()];
coltypes = new int[rsmd.getColumnCount()];
for(int i=0;i<colnames.length;i++){
colnames[i] = rsmd.getColumnLabel(i+1);
coltypes[i] = rsmd.getColumnType(i+1);
rows = new LinkedList();
// this bit checks the cursor position. if not at the start we move it there IF we can
if(!rs.isBeforeFirst()){
if(rs.getType()!=ResultSet.TYPE_FORWARD_ONLY){
rs.beforeFirst();
while(rs.next()){
Object[] arow = new Object[colnames.length];
for(int i=0;i<arow.length;i++){
switch(coltypes){
case Types.BOOLEAN:
arow[i] = new Boolean(rs.getBoolean(i+1));
break;
case Types.DATE:
arow[i] = rs.getDate(i+1);
break;
case Types.INTEGER:
arow[i] = new Integer(rs.getInt(i+1));
break;
case Types.DOUBLE:
arow[i] = new Double(rs.getDouble(i+1));
break;
// I have left out many cases. Adjust as required.
default:
arow[i] = rs.getString(i+1);
rows.add(arow);
public int getRowCount(){
return rows.size();
public int getColumnCount(){
return colnames.length;
public Object getValueAt(int row, int column){
Object[] arow = (Object[]) rows.get(row);
return arow[column];
public boolean isCellEditable(int row, int column){
return false;
public String getColumnName(int column){
return colnames[column];
Save that as SlappyReadOnlyTableModel.
Then invoke in your code like this...
ResulSet rs = // whereever you get result set from.
SlappyReadOnlyTableModel tm = new SlappyReadOnlyTableModel(rs);
rs.close();
JTable display = new JTable(tm);
// now add your table where you likeToday was your lucky day. Please use the API and look at the tutorial for more. http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
Sincerely,
Slappy -
Repeater for XML datasource only showing one row
Hello.
I'm having a problem displaying multiple rows of data from an XML document in
a
jsp net-ui:repeater section. The database call seems to be working fine, the
XML seems to be
put together fine, and the XML document's getting to the jsp via the request.
But, only one
row of data (the first row) shows up.
My .xsd defines TblCompany. TblCompanyDocument was created by Workshop in the
XMLBeans generation.
Advice/guidance/assistance would be much appreciated.
Thanks.
-eric-
Following is in my dataControlImpl.jcs file. It returns seven rows.
* @common:operation
public TblCompanyDocument listCompany() throws SQLException
RowSet company = db.listCompany();
TblCompanyDocument xmlDoc = TblCompanyDocument.Factory.newInstance();
TblCompany xml;
while (company.next())
xml = xmlDoc.addNewTblCompany();
xml.setCompanyId(company.getInt("company_id"));
xml.setCompanyName(company.getString("company_name"));
xml.setWebAddress(company.getString("web_address"));
xml.setUpdateBy(company.getString("update_by"));
xml.setUpdateDt(new XmlCalendar(company.getDate("update_dt")));
company.close();
return xmlDoc;
Following is in my companyController.jpf. It is used to get the results from
my
dataControlImpl in the form of an XML document, place them into a request attribute,
and
pass them on to the index.jsp page as a list of companies to choose from. I've
verified that,
at this point, var has seven rows of data in it.
* Action encapsulating the control method :listCompany
* @jpf:action
* @jpf:forward name="success" path="index.jsp"
* @jpf:catch method="exceptionHandler" type="Exception"
public Forward listCompany()
throws Exception
TblCompanyDocument var = myControl.listCompany();
getRequest().setAttribute( "results", var );
return new Forward( "success" );
Following is in my index.jsp. I've verified that, at this point, the request
has an attribute called
results, and it has the XML document with seven 'rows' of tblCompany in it.
<netui-data:repeater dataSource="{request.results.tblCompany}">
<netui-data:repeaterHeader>
<table cellpadding="2" border="1" class="tablebody" >
<tr>
<td>ID</td>
<td>Name</td>
<td>Web Address</td>
<td>Update By</td>
<td>Update Date</td>
</tr>
</netui-data:repeaterHeader>
<netui-data:repeaterItem>
<tr>
<td><netui:label value="{container.item.companyId}"></netui:label></td>
<td><netui:label value="{container.item.companyName}"></netui:label></td>
<td><netui:label value="{container.item.webAddress}"></netui:label></td>
<td><netui:label value="{container.item.updateBy}"></netui:label></td>
<td><netui:label value="{container.item.updateDt}"></netui:label></td>
</tr>
</netui-data:repeaterItem>
<netui-data:repeaterFooter></table></netui-data:repeaterFooter>
</netui-data:repeater>Well, I get to answer my own question (thanks to a friend). Perhaps this will
help someone
else.
The problem seemed to be in the repeater datasource. When Workshop created the
{pageFlow.allRows} property for me, instead of referring to the subordinate XML
structure as
the name I gave it, it tacked on an ...Array suffix, like:
* allRows
* tblCompanyRowSet
f() tblCompanyArray
I did modify my XML structure during my debugging, and am now afraid to undo it.
Nonetheless, here's how it looks now:
<xs:element name="tblCompany">
<xs:complexType>
<xs:sequence>
<xs:element name="company_id" type="xs:int"/>
<xs:element name="company_name" type="xs:string"/>
<xs:element name="web_address" type="xs:string"/>
<xs:element name="update_by" type="xs:string"/>
<xs:element name="update_dt" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="tblCompanyRowSet">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="tblCompany"/>
</xs:choice>
</xs:complexType>
</xs:element>
And, here's how my repeater code now looks. It works fine. The other scenario
that probably
would've worked with my first newsgroup post would to not have created a tblCompanyRowSet
XML structure, and just made the dataSource={pageFlow.allRows.tblCompanyArray}.
<netui-data:repeater
dataSource="{pageFlow.allRows.tblCompanyRowSet.tblCompanyArray}">
<netui-data:repeaterHeader>
<table cellpadding="2" border="1" class="tablebody" >
<tr>
<td>companyId</td>
<td>companyName</td>
<td>webAddress</td>
<td>updateBy</td>
<td>updateDt</td>
</tr>
</netui-data:repeaterHeader>
<netui-data:repeaterItem>
<tr>
<td><netui:label value="{container.item.companyId}"></netui:label></td>
<td><netui:label value="{container.item.companyName}"></netui:label></td>
<td><netui:label value="{container.item.webAddress}"></netui:label></td>
<td><netui:label value="{container.item.updateBy}"></netui:label></td>
<td><netui:label value="{container.item.updateDt}">
<netui:formatDate pattern="MM/dd/yy: HH:mm z"></netui:formatDate>
</netui:label></td>
</tr>
</netui-data:repeaterItem>
<netui-data:repeaterFooter></table></netui-data:repeaterFooter>
</netui-data:repeater> -
CS_WHERE_USED_MAT only returns one level
Hi all,
I need to get the results that CS15 (where-used) gives me when multi-level is checked.
I need to write a program and was hoping to use FM CS_WHERE_USED_MAT. However, this FM only returns the materials that are one level down. I'm on 4.5b.
Does anyone know what FM I can use that will give me the materials at all levels (like CS15 does). I can use CS_WHERE_USED_MAT and feed back in each material until I reach the end of the levels. But I was wondering if anyone has found a better way.
Thanks,
Mikeyou can refer link:[http://wiki.sdn.sap.com/wiki/display/Snippets/InverseBOMExplosion-ABAP]
or use fm CS_BOM_EXPL_MAT_V2 pass X to field MEHRS -
The result set that contain 10 rows always
Hi all,
I'm wondering if there is some way to produce the result set of a query in 10 rows always, in other word i run a query and i want that the result set in 10 row even if the query dosn't return any row.
I need that row as a placeholder.
thanks
FrancescoHappened to be GUI developer and try to take advantage of SQL,
select * from (select rownum rn, e.* from emp e where rownum<11 and 1=2) e
right join (select rownum rn from dual connect by rownum<11) t
on t.rn=e.rn
RN
EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
DEPTNO
RN
5
8
3
1
2
10
6
7
4
9
10 rows selected.
select * from (select rownum rn, e.* from emp e where rownum<11) e
right join (select rownum rn from dual connect by rownum<11) t
on t.rn=e.rn
RN
EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
DEPTNO
RN
1
7369 SMITH
CLERK
7902 17-DEC-80
800
20
1
2
7499 ALLEN
SALESMAN
7698 20-FEB-81
1600
300
30
2
3
7521 WARD
SALESMAN
7698 22-FEB-81
1250
500
30
3
4
7566 JONES
MANAGER
7839 02-APR-81
2975
20
4
5
7654 MARTIN
SALESMAN
7698 28-SEP-81
1250
1400
30
5
6
7698 BLAKE
MANAGER
7839 01-MAY-81
2850
30
6
7
7782 CLARK
MANAGER
7839 09-JUN-81
2450
0
10
7
8
7788 SCOTT
ANALYST
7566 19-APR-87
3000
20
8
9
7839 KING
PRESIDENT
17-NOV-81
5000
0
10
9
10
7844 TURNER
SALESMAN
7698 08-SEP-81
1500
0
30
10
10 rows selected. -
How to return one ROW with Multiple value seperated by Colon in a SQL Query
Hi,
I have a SQL query as mentioned.
select deptno
from deptI want to mofidfy this query, so that this should return me department list with colon delimeted in one ROW.
10:20:30:40.......Thanks,
DeepakIn 10g:
select rtrim(xmlagg(xmlparse(content deptno || ':')).getstringval(), ':') data
from dept;
DATA
10:20:30:40with apologies for the abuse of XML... -
My table lists only up one row at a time. dynamic don't work
Hi!
I have a table that consists of: ID, NAME, LINK and
CONTENTID.
It's 5 records in it at the moment.
I create a recordset.
I choose all (ID, NAME, LINK and CONTENTID).
It only shows up ONE row. I mark the table and choose
repeating behavior. I still only get up one row.
I follow this tutorial:
http://www.adobe.com/support/dreamweaver/building/users_delete_rcrds_php/users_delete_rcrd s_php03.html
I use Dreamweaver CS3.
Any good advice, cause I haven't got a clue.
I've tried everything: the embassy, the German government,
the consulate. I even talked to the U.N. ambassador. It's no use, I
just can't bring my wife to orgasm.
MarwCan't get it to work. But I start off with this:
1.
http://img521.imageshack.us/my.php?image=01tablexk1.png
After I follow your instructions, and mark
name I get this:
http://img514.imageshack.us/my.php?image=02trselectedzg6.png
But still I only get one post and have to use a Recordset
navigation bar instead.
Marw -
Calling a Stored Procedure with a result set and returned parms
I am calling a stored procedure from a Brio report. The stored procedure returns a result set, but also passes back some parameters. I am getting a message that states that the DBMS cannot find the SP with the same footprint. Besides the result set, the SP returns 3 out parameters: (Integer, char(60), char(40)). Is there something special I need to do in Brio to format the out parameters to be passed back from the SP.
Thanks,
RolandDid you try just declaring the vars?
untested
declare
myCur SYS_REFCURSOR;
myRaw RAW(4);
BEGIN
test (0, 0, myRaw, sysdate, myCur);
END;
Maybe you are looking for
-
No longer sending emails to Groups
Help, All of a sudden I can no longer send emails to groups. It says the server is not accepting the email.
-
How can I add a dip to white at the beginning of a clip?
How can I add a dip to white at the beginning of a clip? I know where to find it on Pr, but I'm new to AE. I have 2 clips that need to transition one to the other. The first clip ends by dipping to white; therefore, I need to either dip to white a
-
There is a great document on the site for configuring ACS 5.X to authenticate voa TACACS+ but with 5.4 - there is possibly an extra step required. https://supportforums.cisco.com/docs/DOC-14273 In 5.4 where you map the Shell Profile to the Authorizat
-
Hello, i am trying to build my first table free website and I need a bit of help. everything is looking fine in dreamweaver but in the broswer two of my div tags (the main conent area and links at the foot of the page seem to disapear. I have done CS
-
Regarding restricted keyfigures
Hi Gurus , can any one tell me about restricted key figures and steps in BI. How can we see which keyfigures are restricted navigation plz. Thanks Shilpa