Unable to loop through a ResultSet (Classic ASP, ADO)

All,
I have inherited a legacy web site and have encountered a problem that I can't get figure out:
The program structure is as follows:
 1. Execute a SQL Server Stored proc and create XML from the result set 
 2. If a condition is met, exceute a second stored proc and hydrate the XML from step one with some more tags
 3. return the XML is the response
Step 1 happens without problems, but when the condition is met the execution halts as soon as I try to do anything with the Result Set. For instance set
RS.ActiveConnection = nothing or do until CustodianRS.EOF both halt execution. and I end up with an empty Response.
Here is the offending code:
if len(trim(strTradingArea)) = 4 then
dim CustodianCN
dim CustodianCMD
dim CustodianRS
dim node
set CustodianCN = server.CreateObject("ADODB.Connection")
CustodianCN.CursorLocation = adUseClient
CustodianCN.Open Application("PANORAMA_SACDETAILS")
set CustodianCMD = server.CreateObject("ADODB.Command")
with CustodianCMD
set .ActiveConnection = CustodianCN
.CommandType = adCmdStoredProc
.CommandTimeout = 300
.CommandText = "p_SACGetAccountCustodiansByTradingArea"
.Parameters("@TradingArea").Value = strTradingArea
set CustodianRS = .Execute
end with
'set CustodianRS.ActiveConnection = nothing
CustodianRS.Sort = "Custodian"
do until CustodianRS.EOF
set node = responseXML.createElement("custodian")
node.setAttribute "id",trim(CustodianRS.Collect("Custodian") & "")
node.setAttribute "parent",trim(CustodianRS.Collect("Parent") & "")
responseXML.firstChild.appendChild(node)
CustodianRS.MoveNext
loop
end if
Does anyone have any suggestions? Any help would be much appreciated, I have already spent a considerable amount of time on this.
Thanks!

I had a minute or two.  Here are some things to think about:
I removed all unnecessary lines of code and indented correctly.  What I immediately see is that you have no error management.  There is also no way to detect an empty recordset.
set CustodianCN = server.CreateObject("ADODB.Connection")
CustodianCN.Open Application("PANORAMA_SACDETAILS")
set CustodianCMD = server.CreateObject("ADODB.Command")
with CustodianCMD
set .ActiveConnection = CustodianCN
.CommandType = adCmdStoredProc
.CommandTimeout = 300
.CommandText = "p_SACGetAccountCustodiansByTradingArea"
.Parameters("@TradingArea").Value = strTradingArea
set CustodianRS = .Execute
end With
CustodianRS.Sort = "Custodian"
do until CustodianRS.EOF
set node = responseXML.createElement("custodian")
node.setAttribute "id",trim(CustodianRS.Collect("Custodian"))
node.setAttribute "parent",trim(CustodianRS.Collect("Parent"))
responseXML.firstChild.appendChild(node)
CustodianRS.MoveNext
loop
My suspicion is that you did not write this.  If you are just trying to change or migrate a web page then I recommend contacting a consultant.  Using a database from a web page is a very tricky task.  If you are not a developer it is highly
unlikely that you will be able to get it to work.
¯\_(ツ)_/¯

Similar Messages

  • Looping through 2 resultsets simultaneously

    I need to set up a loop in which I loop through 2 ResultSets simultaneously and compare them. I have tried to use a simple while (RS1.next() || RS2.next() ), but when I try to read data from RS2 I get an "Invalid Cursor state" error. From my experience with these errors, I think it just means that RS2 isn't looping, but I don't know how to fix it.
    Here's the loop I have:
    while (RS1.next() || RS2.next() ) {
    <%=RS1.getString("Name")%> <%=RS2.getString("Name")%>
    And just to avoid any confusion, what I have written is correct, both tables have a field called 'Name'.
    Can someone please help me?
    Chris

    Unfortunately, there is not necessarily a one-to-one relationship between the Note and Message. However, I am actually using 2 separate statement objects for the resultsets. I know exactly what you mean if there was in fact a 1-to-1 relationship, but unfortunately, since there isn't, I need 2 resultsets. I have tried a few other things since I wrote this and have come close. Here is what I've tried, so others know:
    I've tried using a boolean variable set to true at the beginning and if, after going through the loop, I am at the end of both recordsets, I set it to false. This worked when I didn't have any elements in one of the tables, but, for one reason or another, when I had data in both tables, I got the same Invalid Cursor State error.
    I've also tried using 2 separate boolean variables, one for each of the fields, but this also gives me this error.
    So if anyone else has any ideas to help me out, I'd appreciate it.
    Chris

  • Loop through Query String in ASP

    Hi,
    I am new to ASP and am trying to loop through values in a
    query string
    separated by a comma, for example:
    /site/search/results.asp?ids=19736a,20248a,14952a,19956a
    I need to construct SQL from this something like
    SELECT * FROM MyTable WHERE
    ID = 19736a OR
    ID = 20248a OR
    ID = 14952a OR
    ID = 19956a
    I am just unsure on how to separate all the values from the
    query string.
    Thanks for your advice.

    Oh, in the example below there is no space between the id
    numbers in the
    querystring.
    eg. ids=1,23,456,2
    If you do have spaces then you need to adjust the split
    accordingly
    eg. ids=1, 23, 456, 2
    you would use myIdArray=split(idStr,", ")
    note the space after the comma.
    just make sure you always use the same format in your
    querystring
    Justin
    "Justin Reid" <[email protected]>
    wrote in message
    news:e6osem$dfj$[email protected]..
    > You need to create an array of ids and then add them to
    your SQL.
    > Something like:
    > <%
    > If Request.QueryString("ids") <> "" Then
    > Dim idStr, cnt, varID
    > 'get the string of id'
    > idStr = Request.QueryString("ids")
    > 'create the array
    > myIdArray=split(idStr,",")
    > cnt=0
    > 'loop though the array and add to a new string
    > for i=o to ubound(myIdArray)
    > If cnt > 0 Then varID = (varID & " OR")
    > varID = (varID & " id = " & cStr(myIdArray(i)))
    > cnt=cnt+1
    > next
    > End If
    > %>
    >
    > Then simply add you new SQL segment to your recordset.
    > Something like
    >
    > SELECT * FROM MyTable WHERE" + Replace(varID, "'", "''")
    + "
    >
    > Hope that helps
    >
    > Justin
    >
    > "Shaun" <[email protected]> wrote in
    message
    > news:e6ole1$56v$[email protected]..
    >> Hi,
    >>
    >> I am new to ASP and am trying to loop through values
    in a query string
    >> separated by a comma, for example:
    >>
    >>
    /site/search/results.asp?ids=19736a,20248a,14952a,19956a
    >>
    >> I need to construct SQL from this something like
    >>
    >> SELECT * FROM MyTable WHERE
    >> (
    >> ID = 19736a OR
    >> ID = 20248a OR
    >> ID = 14952a OR
    >> ID = 19956a
    >> )
    >>
    >> I am just unsure on how to separate all the values
    from the query string.
    >>
    >> Thanks for your advice.
    >>
    >
    >

  • Looping through the resultset

    Post Author: Swapna
    CA Forum: Formula
    Hi
      I need to loop through the result set how would i do that here is my scenario
    in the database i have total 10 columns say an example
    a,b,c,d,e,f,g,h,i,j,k and assume i have 100 rows with allthese values in the database now for these 100 rows i have to calculate the summary of those columns and i have written formula something like this but it was not working it was giving me zero dont know plz advise on this
    whileprintingrecords;
    numbervar totalsum;
    totalsum=totalsum((a-b)/100cdefghi-j-k);
    and i want to display this sum in my detail section of report how would i do that
    I Appreciate your help.

    Post Author: SKodidine
    CA Forum: Formula
    Try this and see if you get any results.
    totalsum=totalsum((a-b)/100cdefghi-j-k);
    totalsum := totalsum((a-b)/100cdefghi-j-k);

  • Populate Local XML File, and Loop through it

    I created a local property of type XML.   I want to populate this variable with the results of a SQL query, and store it in local memory.  Then later, I will loop through this file and perform actions.   Basically I am going to have to loop through this resultset many times, and if I can store it in memory, I won't have to re-qurey the DB>
    #1 Is this possible? 
    Right now, I use a repeater on the SQL, and assign the rowset/rowset/row to the local XML Variable.(Assign XML). SHould I use Assign XML, or APpend XML for the Link Type
    THen later I am trying a repeater to loop through the flle, and I have no idea where to point the xpath expression to.
    Thanks for the help in advance,
    JEff

    From what I understand you are trying to do - Rather than repeating on the SQL query you can link the "Result" of the SQL Query action to the local property (type xml) [and yes you just say Assign XML instead of Append or anything else].
    What this would do is assign the local variable the results of the SQL Query in an xMII XML format and then you can further work on this XML.
    But rather than using the local variable you can repeat on the SQL Query Action (the way you are doing currently) and manipulate what ever you want to. There is no question of requerying the DB as ur DB would be queried only one time (the SQL Query Action Block will ensure this) and then the repeater would be repeating only on the resulset rendered by the SQL Query action.
    Did this make it clearer or have I not understood your  problem?

  • How to loop through classic report rows?

    Hi,
    I have a page that has a classic report region. Can I somehow loop through the rows in the report result?
    If I put a checkbox item in the query then using this works fine, but I would not like to add checkbox I just would like to loop through the records.
    FOR I in 1..APEX_APPLICATION.G_F02.COUNT LOOP
    Do something with record having  checkbox item value APEX_APPLICATION.G_F02(i);
    END LOOP;
    TIA,
    Tamas

    Andy,
    What I would like to do is to let the user click a report row, then navigate to a detail form page and display detailed information of the given report row. And should the suer decide to have a look at all the records, then let him/her click a next button on the detail form and display the next row in the report result on the detail form.
    Thanks for the tip. if there is no other way, I will probably do this way.
    Tamas

  • How do I loop through tables, not columns in a table?

    Sorry if this is a long one. My problem is actually quite simple. I am trying to write either an ad hoc PL/SQL block or a stored procedure to loop 18 times (thru 18 tables) and perform a SQL query on those tables, returning 18 resultsets. I would like the results to show up on the screen (or in a spool file, whatever).
    So far I have tried 3 different approaches, none of which have worked.
    1. I tried to assign the select query to a variable (qry) and use EXECUTE IMMEDIATE qry. This forced me thru a variety of errors to declare variables and assign the result to them--EXECUTE IMMEDIATE qry into nm0, nm1, nm2...
    The problem with that was the resultset returned more than the variable was built for as there might be no rows returned, or it might be a thousand rows of data. So I tried changing the variables to VARRAYS, but it gave me a type mismatch as the underlying columns were NUMBER and VARCHAR2.
    DECLARE
         ctr number;
         TYPE NUMLIST IS VARRAY (1000) OF NUMBER;
         TYPE VARLIST IS VARRAY (1000) OF VARCHAR2(15);
         nm0 NUMLIST NOT NULL DEFAULT 1;
         nm1 VARLIST;
         nm2 NUMLIST NOT NULL DEFAULT 1;
         nm3 VARLIST;
         nm17 NUMLIST NOT NULL DEFAULT 1;
         qry VARCHAR2(2000) := 'klx_uln_p000_cells';
    BEGIN
    FOR ctr IN 1..17 LOOP
         IF ctr &lt; 10 THEN
              qry := 'SELECT
              A.DIM_0_INDEX,
              S0.SYM_NAME,
              A.DIM_1_INDEX,
              S1.SYM_NAME,
              A.DIM_2_INDEX,
              S2.SYM_NAME,
              A.DIM_3_INDEX,
              S3.SYM_NAME,
              A.NUMERIC_VALUE,
              B.NUMERIC_VALUE
              FROM
              KHALIX.klx_uln_p00'||ctr||'_cells A,
              KHALIX.klx_ucn_p00'||ctr||'_cells B,
              KHALIX.KLX_MASTER_SYMBOL S0,
              KHALIX.KLX_MASTER_SYMBOL S1,
              KHALIX.KLX_MASTER_SYMBOL S7
              WHERE
              A.DIM_0_INDEX=B.DIM_0_INDEX AND
              A.DIM_1_INDEX=B.DIM_1_INDEX AND...
              A.DIM_7_INDEX=S7.SYM_INDEX';
         ELSE
              qry := 'SELECT
              A.DIM_0_INDEX...
              A.DIM_7_INDEX=S7.SYM_INDEX';
         END IF;
         BEGIN
         dbms_output.put_line('SELECT FOR KLX_ULN_P00'||ctr||'_CELLS');
         dbms_output.put_line(nm16);
         dbms_output.put_line(nm17);
         EXECUTE IMMEDIATE qry into nm0,nm1,nm2,nm3,nm4,nm5,nm6,nm7,nm8,nm9,nm10,nm11,nm12,nm13,nm14,nm15,nm16,nm17;
    --     dbms_output.put_line(qry);
         dbms_output.put_line(nm16);
         dbms_output.put_line(nm17);
         EXCEPTION
              WHEN NO_DATA_FOUND THEN
                   dbms_output.put_line('No data found for Query '||ctr);
         END;
    END LOOP;
    EXCEPTION
         WHEN NO_DATA_FOUND THEN
              dbms_output.put_line('No data found for Query '||ctr);
    END;
    2. So then I used REF CURSOR to create a stored procedure and return the values. That allowed me to run my query AND tokenize the tablenames with a counter so that it would loop through the different tables! However, I still could not get it to display the results without going to SQL Plus and typing 'print c;'.
    3. So, finally I tried to create a looping wrapper around the ref cursor to have some variable (ctr) increment so my query would get performed on table0_cells through table17_cells. This, too, did not work.
    If I manually go to SQL Plus and type:
    variable ctr number
    begin
    :ctr := 1;
    end;
    exec dupe_find(1,:c);
    it will execute for the first table (klx_uln_p001_cells) and I can then type 'print c' to see what was returned. But when I try putting this within a wrapper PL/SQL block with a Loop to make ctr go from 0 - 17 (to loop through table_names klx_uln_p000_cells to klx_uln_p017_cells), it does not work.
    Help! It should be very simple to loop through tables, shouldn't it? I just want a script that will loop through tables, perform a query on each table and display the results. For some reason, I can only find documentation examples on looping through columns that are all in the same table.
    Dave

    Here's a working example using your first strategy ...
    create table t1 (id number);
    create table t2 (id number);
    insert into t1 values (100);
    insert into t1 values (101);
    insert into t2 values (200);
    insert into t2 values (201);
    declare
    v_table_name user_tables.table_name%type;
    type ttab_id is table of t1.id%type index by binary_integer;
    tab_id ttab_id;
    begin
    for i in 1 .. 2 loop
    v_table_name := 't' || i;
    execute immediate 'select id from ' || v_table_name
    bulk collect into tab_id;
    dbms_output.put_line('query from ' || v_table_name);
    for j in 1 .. tab_id.count loop
    dbms_output.put_line(tab_id(j));
    end loop;
    end loop;
    end;
    There are many other ways to do this (especially if you need to do more than just print out the data).
    Richard

  • Classic ASP - "ORA-01722: invalid number" using OraOLEDB.Oracle driver

    I am working on doing some maintenance updates to a Classic ASP website, and I need to be able to run an insert/update statement for putting values into a lookup table. I am currently running into an "ORA-01722: invalid number" error when trying to use ADO and bind variables for my insert statement.
    Below is an example of a table that I am having problems with:
    CREATE TABLE "MATMGR"."TEST_SWING_TABLE"
    (     "TABLE1_ID" NUMBER(4,0) NOT NULL ENABLE,
         "TABLE2_ID" NUMBER(4,0) NOT NULL ENABLE,
         CONSTRAINT "TEST_SWING_TABLE_PK" PRIMARY KEY ("TABLE1_ID", "TABLE2_ID")
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS" ENABLE
    ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS" ;
    Here is some snippet code of the basic functionality I am trying to get to work:
    ''START CODE''
    Dim connDb, cmdDoseInsert
    Set connDb = Server.CreateObject("ADODB.Connection")
    connDb.CursorLocation = adUseClient ' Setup to return RecordSet
    connDb.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source={host};User ID={user id};Password={password}"
    connDb.Open()
    Set cmdDoseInsert = Server.CreateObject("ADODB.command")
    Set cmdDoseInsert.ActiveConnection = connDb
    cmdDoseInsert.CommandType = adCmdText
    cmdDoseInsert.NamedParameters = true ' Set the command object to use named parameters
    cmdDoseInsert.Prepared = true
    cmdDoseInsert.CommandTimeout = 0
    cmdDoseInsert.CommandText = "INSERT INTO TEST_SWING_TABLE (TABLE1_ID, TABLE2_ID) VALUES (:P_TABLE1_ID, :P_TABLE2_ID)"
    cmdDoseInsert.Prepared = true
    cmdDoseInsert.Parameters.Append cmdDoseInsert.CreateParameter("P_TABLE1_ID", adNumeric, adParamInput)
    cmdDoseInsert.Parameters.Append cmdDoseInsert.CreateParameter("P_TABLE2_ID", adNumeric, adParamInput)
    '... START: While Looping
         cmdDoseInsert.Parameters(0).Value = {some numeric value}
         cmdDoseInsert.Parameters(1).Value = {some numeric value}
         cmdDoseInsert.Execute
    '... END: Looping
    ''END CODE''
    What I have been able to find out so far is that there is some type of issue with numeric values getting translated right when sending two and retrieving from Oracle in ASP. So, does anyone have any thoughts on how to resolve this as I would like to use parameterized SQL to improve application performance?
    I am connecting to a developmental server running Oracle 9.2

    Ok, in my slightly larger example I found out that for what ever reason my named parameters are not being enforced, and so I had to make sure that the parameters were in the same order as they appeared in the SQL. To be on the save side, I did this when they were added as well as when I was assigning values to them.
    Can anyone tell me if this is an Oracle issue or a ASP issue?

  • Loop through checkbox in Oracle APEX 4.2 (using JQuery Mobile)

    Hello!
    I want question text and a report containing the possible answers is shown on a page. An answer can be selected by clicking on the checkbox. After hitting the submit button, the selected checkboxes containing the Answer Text, an answer_id and the current session_id are to be inserted into a table within the database.
    Within Oracle APEX 4.2, I am using a classic report to achieve this. Thich is actually a bad solution, because the checkboxes within the report are shown as simple HTML checkboxes, instead of neat JQueryMobile checkboxes). Anyway, this is my current solution:
    Is use this code for creating the classic report:
    SELECT APEX_ITEM.CHECKBOX(1,answer_id), answer_id, answer_text
    FROM ANSWERS
    WHERE question_ID = :P10_Question_ID;
    The insert of the data is done via the on submit process "On Submit - After Computations and Validations"
    This is the code for the on submit process:
    DECLARE var_session_id NUMBER := :P0_SESSION_ID;
    BEGIN
    FOR i in 1..APEX_APPLICATION.G_F01.COUNT LOOP
    INSERT INTO STUDENT_ANSWERS (answer_id, answer_text, session_id)
    SELECT a.answer_id, a.answer_text, var_session_id
    FROM ANSWERS a WHERE a.answer_id = APEX_APPLICATION.G_F01(i)
    END LOOP;
    COMMIT;
    END;
    But this solution does not work. Instead, nothing is inserted into the database.
    I don't know why the process is not inserting into the database, maybe there is something wrong with this line here WHERE a.answer_id = APEX_APPLICATION.G_F01(i) ?
    I even tried a simple update process for testing purposes, but this doesnt work either:
    BEGIN
    FOR i in 1..APEX_APPLICATION.G_F01.COUNT LOOP
    UPDATE STUDENT_ANSWERS SET text = APEX_APPLICATION.G_F03(APEX_APPLICATION.G_F01(i))
    WHERE am_id = APEX_APPLICATION.G_F02(APEX_APPLICATION.G_F01(i));
    END LOOP;
    COMMIT;
    END;
    Can anybody tell me how to loop through a checkbox within ORACLE APEX 4.2 and how to insert the values ANSWER_ID, ANSWER_TEXT and SESSION_ID into the table STUDENT_ANSWERS after hitting the submit button? If you would know how to do it without using a report but a simple checkbox, this would be even more helpful for me!

    I would start by putting this after submit, to check the contents of the array.
    apex_debug.message('count:'||apex_application.g_f01.COUNT);
    FOR i IN 1..apex_application.g_f01.COUNT LOOP
        apex_debug.message('i:'||i||':'||apex_application.g_f01(i));
    END LOOP;
    Then compare the contents with your answers table.

  • Problem looping through recordset

    Hi,
    I am having a problem with the following code. In the test case, the recordset returns more than one record. Only one record is inserted, and the loop aborted after the insert. If I take out the insert statement the loop cycles through for every record. I do not believe there is anything wrong with the insert statement, as the first record is inserted. Any help would be appreciated.
      while(rs.next()){
                     System.out.println("test");
                     String equip = rs.getString("EQUIP");
                     String pm = rs.getString("PM");
                     String lim = rs.getString("LIMIT");
                     String item_val = rs.getString("ITEM_VALUE");
                     String source = rs.getString("SOURCE");
                     myStatement.executeQuery("INSERT INTO TESTTBL(ACTION,STATUS,TOOL,REMARK) VALUES('STACK VALIDATION','UPDATED', '" + equip + "','LIMIT: " + lim + " - VALUE: " + item_val + " SOURCE: " + source + "')");
                     System.out.println("INSERT INTO TESTTBL(ACTION,STATUS,TOOL,REMARK) VALUES('STACK VALIDATION','UPDATED', '" + equip + "','LIMIT: " + lim + " - VALUE: " + item_val + " SOURCE: " + source + "')");
                 }

    Did rs come from myStatement?
    From http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSet.html :
    A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results.
    You have to use two different statements: one for the rs that you're looping through and one for the insert that occurs while still using the first rs.

  • Loop through result set and delete row

    so here is what I need -
    I have a query that pulls rows from the Database through a stored procedure.(these are properties in an area)
    Before I start looping through the query, I need to check the distance between my current location and the property. If it less than 5 miles, only then should I display that property. The distance in miles will be chosen while submitting the search form.
    So is there a way to delete rows from the result set based on the criteria? Or
    Is there a better way to accomplish this? I am using the the google api to get the latitudes and longitudes. The other issue to keep in mind is the load time.
    Thanks

    You can do this the easy way or the hard way.  Depends on whether your condition that needs to be checked can be expressed in the form of a SQL where clause.  If it can, then do what BKBK suggested, and use a query of query to create a new resultset that only has the rows from the original resultset that don't meet your condition.
    If the calculation of the condition is more complex, then do a CFLOOP over the query and examine each row to see if you want to keep it or toss it.  if you want to toss it, the delete that row - there is a function in CFLIB.ORG called querydeleterow that should help you.  Or, you could just clear out the row's contents and then do the query of query as described in BKBK's post to create a new resultset that doesn't include the blank rows.

  • Looping through 2 Result Sets - Not working-HELP!!

    This code loops through my first result set fine.....so I take the first part number from the result set, do a second result set to bring back all part conditions associated with that part number and compare them to see if they are all the same. When it hits the second loop with the second result set, it only loops once. I know this because of my system.out.println only print once.....can someone see where I'm going wrong....thanks in advance....
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    DataSource ds = this.getDataSource();
    HttpSession sess = req.getSession();
    if (sess == null)
    res.sendRedirect(/error.html");
    else
    synchronized(sess)
    UtilParts part = (UtilParts)sess.getValue("UtilParts.PARTS");
    String[] partNumbers = new String[10];
    for(int index=0; index < partNumbers.length; index ++)
    partNumbers[index] = req.getParameterValues("partNumber"+index)[0];
    partNumbers[index] = partNumbers[index].trim();
    String partDesc = req.getParameterValues("partdesc")[0].toUpperCase();
    partDesc = partDesc.trim();
    int rowsCounted = 0;
    for(int index = 0 ; index < partNumbers.length; index ++)
    if(partNumbers[index].equals(""))
    rowsCounted ++;
    Connection conn = null;
    ResultSet resultSet = null;
    ResultSet resultSetMultCond = null;
    PreparedStatement getPartInfo = null;
    Statement getMultPartCond = null;
    String sqlMultCond = null;
    String sql = null;
    try
    conn = ds.getConnection(id,pass);
    conn.setReadOnly(true);
    if(partDesc.equals(""))
    sql = "SELECT #PART,#PDESC,#CONDS,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE #PART LIKE '";
    boolean first = true;
    for (int i=0; i < partNumbers.length; i++)
    if (!partNumbers.equals(""))
    if (!first)
    sql += "%' OR #PART LIKE '";
    sql += partNumbers;
    first = false;
    sql += "%' AND #RECDT BETWEEN 20010816 AND 20020816 GROUP BY #PART,#PDESC,#CONDS ORDER BY #PART";
    getPartInfo=conn.prepareStatement(sql);
    resultSet = getPartInfo.executeQuery();
    if(!partDesc.equals(""))
    String sqlDesc = "SELECT #PART,#PDESC,#CONDS,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE #PDESC LIKE ? AND #RECDT BETWEEN 20010816 AND 20020816 GROUP BY #PART,#PDESC ORDER BY #PART";
    getPartInfo = conn.prepareStatement(sqlDesc);
    getPartInfo.setString(1,partDesc + "%");
    resultSet = getPartInfo.executeQuery();
    Vector enum = new Vector();
    int rowsadded = 0;
    while (resultSet.next())
    rowsadded += 1;
    UtilParts utilityPart = new UtilParts();
    String s = (String)resultSet.getString("#PART");
    s = s.trim();
    utilityPart.setPartNumber(s);
    String t = (String)resultSet.getString("#PDESC");
    t = t.trim();
    utilityPart.setPartDesc(t);
    int resultCount = 0;
    int sameCond = 0;
    String storeName = null;
    String holdName = "No";
    int i = resultSet.getInt("PCOUNT");
    String cond;
    if(i == 1)
    String c = (String)resultSet.getString("#CONDS");
    c = c.trim();
    if(c.equals(""))
    cond = "N/A";
    else
    cond = c;
    utilityPart.setPartCondition(cond);
    utilityPart.setPartCount(i);
    else
    sqlMultCond = "SELECT #PART,#CONDS,COUNT(*) AS MCOUNT FROM MYLIB WHERE #PART = '" + s + "' AND #RECDT BETWEEN 20010816 AND 20020816 GROUP BY #PART,#CONDS ORDER BY #PART";
    getMultPartCond = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_SENSITIVE,java.sql.ResultSet.CONCUR_UPDATABLE);
    resultSetMultCond = getMultPartCond.executeQuery(sqlMultCond);
    int row =0;
    while(resultSetMultCond.next())
    row += 1;
    System.out.println("Row: " + row);
    resultCount = resultSetMultCond.getInt("MCOUNT");
    System.out.println("MCount: " + resultCount);
    if(holdName.equals("No"))
    System.out.println("You are in the no loop");
    storeName = (String)resultSetMultCond.getString("#CONDS");
    holdName = storeName;
    sameCond += 1;
    System.out.println("Same condition: " + sameCond);
    System.out.println("StoreName: " + storeName);
    System.out.println("HoldName: " + holdName);
    else
    storeName = (String)resultSetMultCond.getString("#CONDS");
    if(holdName.equals(storeName))
    sameCond += 1;
    System.out.println("Same condition: " + sameCond);
    System.out.println("StoreName: " + storeName);
    System.out.println("HoldName: " + holdName);
    resultSetMultCond.close();
    getMultPartCond.close();
    if(resultCount == sameCond)
    System.out.println("resultcount equals samecount");
    utilityPart.setPartCount(1);
    utilityPart.setPartCondition("same conditions everywhree");
    else
    System.out.println("resultcount not equal samecount");
    utilityPart.setPartCount(i);
    utilityPart.setPartCondition("");
    enum.addElement(utilityPart);
    }//end of first while
    if (rowsadded == 0 )
    res.sendRedirect("/PartNotFound.html");
    sess.putValue("PARTS",enum);
    resultSet.close();
    conn.close();
    getServletConfig().getServletContext().getRequestDispatcher("/NextQuery.jsp").forward(req,res);
    return;
    catch (SQLException e1)
    System.out.println(e1.getMessage());
    e1.printStackTrace();
    res.sendRedirect("/FindPartSQLError.htm");
    }//end of synchronized session
    }//end of else
    }//end of method

    Got the answer...changed my select statement in my second loop, did a group by CONDS which of course if they are all the same....the result set would only have one value therefore the loop will only execute once...took out the group by CONDS and ran fine....

  • Trying to loop through records

    Hi
    I trying to loop through my records and write to a database each time, but my code only seems to write the first time through...
              //check for the stock levels...
              Iterator stockLevels = getItems().iterator();
              pstmt = dbConn.prepareStatement(sql_bundle.getString("findStock"));
              while (stockLevels.hasNext()) { 
                   CartItem stockL = (CartItem) stockLevels.next();
                   pstmt.setString(1, stockL.getProduct().getISBN());
                   ResultSet rscp = pstmt.executeQuery();
                   if(rscp.next()){
                        if (rscp.getInt("STOCK_LEVEL") > stockL.getQuantity()) {
                             int newAmount = rscp.getInt("STOCK_LEVEL") - stockL.getQuantity();
                             PreparedStatement pstmte = dbConn.prepareStatement(sql_bundle.getString("updateStock"));  
                             pstmte.setInt(1, newAmount);
                             pstmte.setString(2, stockL.getProduct().getISBN());
                             pstmte.executeUpdate();
                        } else {
                             cat.error("Right Bloddy mess");
                                 throw new Exception();
                   }else{ 
                        throw new Exception("No results from known good query.");
              pstmt.close();I get the following error in my browser:
    org.apache.jasper.JasperException
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
    and no errors when I compile using javac...
    Thanks

    excellent my looping is working...
    thanks

  • Looping through Collection

    Hello I need to loop through the collection to process 500 records at a time from the resultset.
    how do i do this?
    I have created another variable of same type as resultset output variable type. but not sure how to assign nodes 1 to 1000 to the new variable.

    Hi,
    You can loop over your collection with a while loop. The following is from the bpel samples directory (112.Arrays) adapted to your needs. Define the variables:
    <variable name="iterator" type="xsd:integer"/>
    <variable name="count" type="xsd:integer"/>
    <variable name="xpath" type="xsd:string"/>
    Set the initial values:
    <assign name="SetInitialValues">
    <copy>
    <from expression="1"/>
    <to variable="iterator"/>
    </copy>
    <copy>
    <from expression="ora:countNodes('input', 'payload','/tns:collection/tns:item')"/>
    <to variable="count"/>
    </copy>
    </assign>
    Make a while loop:
    <while condition=" bpws:getVariableData('count') >= bpws:getVariableData('iterator')">
    <sequence>
    <assign name="setAttribute">
    <copy>
    <from expression="concat('/tns:collection/tns:item[',bpws:getVariableData('iterator'),']/tns:value')"/>
    <to variable="xpath"/>
    </copy>
    <copy>
    <from expression="bpws:getVariableData('input','payload',bpws:getVariableData('xpath'))/>
    <to variable="output" part="payload" query="/tns:recordVariable/tns:value"/>
    </copy>
    <!--
    Place here your own actions to be executed for every row
    -->
    <copy>
    <from expression="bpws:getVariableData('iterator') + 1"/>
    <to variable="iterator"/>
    </copy>
    </assign>
    </sequence>
    </while>
    So the trick is to dynamically build an xpath expression based on the while loop counter.
    Kind Regards,
    Andre

  • Looping through records... LC 8.0

    Hi there
    It seems easy enough to get the first record from a DB into a Form - but for the life of me I cannot find a way to loop through all the records (like mail merge) and enter all the records?
    Could someone please point me in the right direction?
    Thanks

    Hi Paul
    That method would appear to be dependent upon a click method with buttons.
    Apart from the fact that it is time consuming, I can get the end result using .NET and iTextSharp (or ActivePDF Toolkit in asp.NET) to produce 'bulk' pdf documents by loading everything into a DataTable and running through a For loop for each row in the DataTable.
    These forms would be a 'one off' for each new Customer, with an average of 120 records, so was looking for a 'quick and dirty' approach - as you may gather we have LC but not used it very much at all, so perhaps I was missing something!

Maybe you are looking for

  • Why Is There A loss In Quality When I impoer a Minidv tape into Imovie 08

    I have the latest version of Imovie and this is my first Mac. I am using SD MiniDV camcorder (NTSC). I import the entire tape into iMovie. Then I export it to a large h.264 m4v file. I am somewhat disappointed about the picture quality of the m4v fil

  • OS Version:_6.1.7601.2.1.0.256.1

    Hi, I am frequently getting below error could any help me to fix this issue Problem signature:   Problem Event Name: BlueScreen   OS Version: 6.1.7601.2.1.0.256.1   Locale ID: 1033 Additional information about the problem:   BCCode: 1a   BCP1: 000417

  • ORABPEL-09705

    Hi All, Using JDeveloper 11.1.1.5 , Oracle SOA Suite 11g BPEL A developer gave me a URL = http://AVEPOC04/AFDM/AFDMService.svc Steps I took: 1.Used IE to get the source data , that I used to create a WSDL file. 2.Created a Partner link in BPEL with t

  • Firefox will only print the first page of many from web. solution please.

    i read on google it has something to do with CSS and frames but as i am not an experienced programmer i have no idea how to change how firefox copes with these whilst trying to print a multi-page document from the web (such as guitar tabs or emails)

  • Active Directory logins from Windows to Final Cut Server

    While I did manage to solve my main problem with Integrating AD with Final Cut Server at this one site.... It turns out that there a typo in the kerberos config file. Ooops. Now logins in from Mac OS using AD credentials works well. Unfortunately, I