Problem with ResultSet in a loop

hi,
i have a probleme with ResultSet when, my code is bellow
ResultSet rs = stmt.executeQuery(sql);
sql="SELECT NAME FROM prestationtemp";
rs = stmt.executeQuery(sql);
String sqlDel="";
while (rs.next())
sqlDel="Delete from prestation where NAME="+rs.getString("NAME");
stmt.executeQuery(sqlDel);
the problem is that the loop iterate just once like if there is just one record, and if I remove stmt.executeQuery(sqlDel); from the loop it iterate normaly.
thanks in advance.

you will need to use 2 Statments e.g.
Statement stmt1 = connection.createStatement();
Statement stmt2 = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
sql="SELECT NAME FROM prestationtemp";
rs = stmt1.executeQuery(sql);
String sqlDel="";
while (rs.next())
sqlDel="Delete from prestation where NAME="+rs.getString("NAME");
stmt2.executeQuery(sqlDel);
} When you reuse a Statement, any resultsets previously created are automatically closed.
Looking at your code, it seems that you only need 1 SQL call:
Delete from prestation where NAME in (SELECT NAME FROM prestationtemp)
Much more efficient!

Similar Messages

  • Problem with two parallel While loops

    I have a serious problem with controlling two parallel While Loop. Here is the deal:
    I have written a VI to send a series of commands called Cycle through Serial Port to a custom hardware. One of these commands is setting motor pressure by sending it's command and changing it's voltage. After setting desired pressure I have to read and control motor pressure, again through serial port in a parallel loop. There is a Pressure Sensor in system and I can obtain current's motor pressure by sending a command and receiving pressure value. In the first While loop I send some commands to hardware including Pressure Setting Command trough a state machine. In the second While Loop I read pressure value and then decide to increase motor voltage or decrease  it. Now the problem is in communicating these two loops. In cycle after "Init" state when state reaches "Pressure 2 Bar" motor voltage will increase. Meanwhile I have to control this voltage in parallel While Loop. As you can see I used Local Variable to communicate between these two loops. The problem is that loops are not synchronized. Specially when I switch to "Pressure 3.8 Bar" state during cycle running control loop (second while) is still working based on "Pressure 2 Bar" state not 3.8 bar. Because of this motor pressure goes to 3.8 bar for a sec (becuase of  "Pressure 3.8 Bar" state) and comes back to 2 bar (because the second while still has not gotten that new state,most probably cause of all the delays in the loop)  and after couple seconds it goes back to 3.8 bar.
    I really don’t know what to do. Is there a way to fix this? Or I should consider a better way to do this?
    I went through Occurrence Palette but couldnt figure out how to embed that in the VI. 
    Sorry for my poor English. I attached VI and it's subVIs as a LLB file. I can explain more details if somebody wants. 
    Attachments:
    QuickStartCycle.llb ‏197 KB

    I make it a point to NEVER have a WAIT function inside a state machine.
    It sort of defeats the purpose, which I define as "Examine current state; decide whether you've met the conditions to advance to another state, then get out".
    For example, I have a single state machine VI controlling four identical instruments, via TCP connections.
    For some functions, that means issuing a command, waiting 60 seconds, then reading results.
    If I waited INSIDE the state machine, then it's tied up waiting on one device and cannot handle any others.
    Not a good plan.
    To handle this, I have a loop which calls the state machine.  After issuing the command, the state goes to "Waiting on Response", and there is a target time of 60 seconds from now.
    It's called over and over in that state, and each time merely compares NOW to the target time.  If NOW is past the target, then we read the results.
    the state machine can tell the caller when to call back; that's how I distinguish between an urgent need and nothing-to-do.
    By having the CALLER do the waiting, instead of the state machine itself, the state machine is free to handle another device, or do something else on the same device.
    You should be calling the state machine over and over and over anyway.  So, have the state machine "control the pressure" on every call, and THEN examine whatever state it's in.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • Problem with DAQ in while loop and Graphs

    Hello,
    I'm new here so I apologize if I posted this on the wrong board  
    This is my "situation":
    I need to make a simple PID controller which takes information (process variable) from an outside source (a NI's DAC connected through the USB port ) which is accomplished using NI-DAQ as an input, and the PID's output goes to the second NI-DAQ which is also connected using DAC to an actuator which in my case regulates the air pressure. (VI attached)
    My problem is the following.
    Both of the NI-DAQ I placed using DAQ Assist, require to be in a while loop.
    -If I place them in separate loops, I have the problem of passing information between the Input NI-DAQ and the PID, and also between the PID and the Output NI-DAQ.
    -If I place them both in one big loop, an error occurs saying that the selected buffer size is too small (Error -200609).
    The timing settings for the DAQ's N samples, 100 samples to read at the rate of 1k (I also tried with Continuous samples and many different combinations of Samples to Read an Rate but without success).
    Should I wire them with the same dt(s)?
    The other thing I need to do (I'm also writing it here in order not to open new topics) is show the following 3 signals on a Graph (process variable (dynamic data type)(range 4mA - 20mA), PID output (double)(range 4mA - 20mA), and the Set Point (double)(range 0 to inf))
    Firstly, is it possible to show the first two on a scale from 0 to 100 without changing the PID's output which needs to be 4-20?
    Secondly, which graph should I use if I have different data types? (I tried the Waveform Chart, and succeeded in showing the first two; the third just messes everything up)
    I would also have to make a legend explaining which signal is which (I see that this is possible with the Mixed Signal Graph).
    I know this is probably too much to ask, but I'd be grateful for any help
    Thank you in advance
    Attachments:
    PID while.vi ‏100 KB

    My problem is the following. Both of the NI-DAQ I placed using DAQ Assist, require to be in a while loop.
    -If
    I place them in separate loops, I have the problem of passing
    information between the Input NI-DAQ and the PID, and also between the
    PID and the Output NI-DAQ.
    This is the best option---Use QUEUE or Functional global or something else to tranfer the data to and fro
    How  do I make that QUEUE or Functional global?
    -If I place them both in one big loop, an error occurs saying that the selected buffer size is too small (Error -200609).
    Have
    you tried increasing the buffer? Is the acquisition happening
    parallelly (means to say the first DAQ not wired (error terminal) to
    second DAQ)
    Well the buffer is, at least how I understood it, the option Number of Samples when in Continuous Samples mode. Concerning the parallel acquisition, do you mean I should wire the error ports of both of the DAQs?

  • Problem with cfhttp in a loop

    Hi,
    I am reading an xml file that contains emails with attachments (one email per item/node, but may contain multiple attachments).  I am trying to save the attachments to our server.  So I'm looping over the multiple attachments of a single email and using cfhttp to GET the attachments from another server and save them with the same filename on our server.
    The problem is that it works for the first attachment - it's saved to the server, status code is 200 OK - awesome!  But for any attachments after that, it does not save them and throws a Conection Failure error.  No matter what attachments they are.
    In trouble shooting I tried several things.  First, inside of my loop of attachments, I can hardcode the cfhttp calls with the url and filename of the attachments - one right after the other - and all is perfect everytime!!  But it obviously needs to be dynamic.  I also tried to save a list of the attachment urls from the loop, and then call a separate cfhttp tag for each attachment in the list (so again, was in a loop) and it works for the first attachment in the list and not for the others (same errors as above).
    Here's a simplified version of the code.  I can't put in the real xml url, and when I set the "attachmentFilename" I left out that code because it works and is too much code.  Also, the XML works fine.  Please let me know if you have any suggestions, and of course, if you need more info from me!!
    Thanks so much,
    Kirsten
    <cfoutput>
    <cfhttp url="https://www.myxml.com/example.xml" method="get" resolveurl="no" />
    <cfset myXML = trim(cfhttp.FileContent)>
    <cfset myXML = xmlParse(myXML)>
    <cfset theRoot = myXML.XmlRoot>
    <cfset numChildren = arrayLen(theRoot.XMLChildren[1].XmlChildren)>
    <cfloop index="i" from="6" to="#numChildren#">
        <cfset attachments = theRoot.XMLChildren[1].XMLChildren[i]["attachments"].XmlText>
        <cfif ListLen(attachments, "|^|") gt 2>
            <cfset loop_unid = theRoot.XMLChildren[1].XMLChildren[i]["unid"].XmlText>
            <cfset counter = 0>
            <cfset attachmentArray = ListToArray(attachments, "|^|")>
            <cfloop from="1" to="#ArrayLen(attachmentArray)#" index="k">
                <cfset counter = counter + 1>
                <cfset attachmentURL = attachmentArray[k]>
                <cfset attachmentFilename = Replace(attachmentArray[k],"strip the url from the filename in the url","")>
                <cfhttp url="#attachmentURL#" method="get" resolveurl="no" timeout="120" path="D:\my_servers_path\attachmentFolder\" file="#attachmentFilename#">
                attachment counter: #counter#<BR />
                cfhttp.statusCode: #cfhttp.statusCode#<BR />
                cfhttp.errorDetail: #cfhttp.errorDetail#<BR />
            </cfloop>
        </cfif>
    </cfloop>
    </cfoutput>
    Output Results:
    attachment counter: 1
    cfhttp.statusCode: 200 OK
    cfhttp.errorDetail:
    attachment counter: 2
    cfhttp.statusCode: Connection Failure.  Status code unavailable.
    cfhttp.errorDetail: I/O Exception: peer not authenticated
    attachment counter: 3
    cfhttp.statusCode: Connection Failure.  Status code unavailable.
    cfhttp.errorDetail: I/O Exception: peer not authenticated

    We've seen the peer not authenticated error quite a bit on our CFHTTP calls - are you trying to access the URLs via HTTPS?  It seems the SSL certificate keystore that CF ships with does not contain all the vendor SSL certificates out there - when CF can't authenticate a cert, it throws that "Connection Failure / Peer not authenticated Error".  In order to fix the issue, you have to import the SSL certificate of the site you are trying to access into the CF cert store on your server(s).  If you are using multiple servers, you will have to import the cert on each server.
    I'm sure a google search will turn up a step by step guide on how to do this, but the basic steps are:
    Go to a page on the SSL server.
    Double-click the lock icon.
    Click the Details tab.
    Click Copy To File.
    Select the base64 option and save the file.
    Copy the CER file into ColdfusionDir\runtime\jre\lib\security
    Run the following command from the same directory (keytool.exe is located in ColdfusionDir\runtime\jre\bin) ..\..\bin\keytool.exe -import -keystore cacerts -alias UniqueName -file filename.cer
    Restart Coldfusion
    Hope that helps!
    - Michael

  • Problem with  AT command in LOOP

    Hi Experts,
    here i ve a problem like, in my table there are 3 PSPHI(projects) values,
    if i loop n calculate the sum it is getting total amt for 3 PSPHI values,
    but i want every end of PSPHI i need sum.
    the below code is working fine if there is no AT coomand, if i put AT END OF PSPHI it is giving 00.00 values.
      LOOP AT it_final into it_output.
       AT END OF PSPHI.
        if it_final-wrttp = '04'
           AND it_final-vorga = 'COIN' 
           AND it_final-beltp  = '02'
           AND it_final-versn = '000'.
       t_pla_rev = t_pla_rev + it_output-wlp01.
        MOVE it_output-wlp01 TO pla_rev.
        sum = sum + pla_rev.
          if sy-subrc EQ 0.
            else.
            write:/10 ' u r not ok'.
        endif.
    e  ndif.
    append it_output.
    *ENDAT.
    ENDLOOP.
    write:/10 'total amt is', sum.
    could anybady check where i gone wrong pls...
    Thanks in advance,
    sudharsan.

    Hi,
    What is your table structure.
    The command  AT ........ENDAT  work in sequential order.
    Let me explain with example.
    if your table itab has two column  column1 and column2
    loop at itab into wa.
    at new column2.
    // This will execute when the Value of column 1 change or column2
    // change.
    endat.
    endlloop.
    The solution of your problem is.
    Change your internal table column order ,
    Put the column first for which you want to calculate the sum.
    Thanks & Regards
    Kulvendra Kumar

  • Urgent: Character Set Problem with ResultSet

    When I use normal statement as below the program works well:
    Class.forName("oracle.jdbc.driver.OracleDriver");
    String URL = "jdbc:oracle:thin:@10.1.20.8:1521:ora92";
    Properties prop = new Properties();
    prop.setProperty("user","unistock");
    prop.setProperty("password","unistock");
    Connection myconn = DriverManager.getConnection(URL, prop);
    if (myconn == null) {/ to do:.... }
    // in the table, the name, address are defined
    // as varchar2(20), and are in the format of
    // Chinese characters.
    String sql = "select name, address from tbl_node";
    Statement mystmt = myconn.createStatement(sql);
    ResultSet myresult = mystmt.executeQuery(sql); ......
    In such way, I can get the String object of NAME and ADDRESS, which are all Chinese character string.
    But when I produce the ResultSet objects that are scrollable in below way it fails to get original string:
    //.... the same as before
    Statement mystmt = myconn.createStatement(sql,
    ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
    ResultSet myresult = mystmt.executeQuery(sql); ......
    What I get from such way are strings which lost the highest bit information and I can't 'translate' they to the original ones, because maybe they are mixed with Chinese characters and English characters.
    What happens when I create the scrollable Statement object? And how can I fix such problem?

    hi manidhar,
    I am also facing the same problem.In my case the characters are getting garbled when it is passed to a javaScript function.
    Did u find a solution.
    If yes please post it.
    thanks in advance

  • A problem with delays in timed loops and DAQ

    I am programming a simulation for nuclear rewetting for a visitor centre at my company in Switzerland. It involves heating a "fuel rod" and then filling the chamber with water. The pump automatically starts once the rod core reaches 750C. After this, a requirement stipulates that flow rate be checked to ensure the pump is operating at the necessary conditions. If it isn't, the heater must be shutdown to avoid, well... meltdown. However, we must allow 10 seconds for the pump to respond, while still allowing a DAQ rate of 10-100Hz.
    The challenge is that I can't add a delay in my main loop else delay all acquisition, but I can't figure out how to trigger a peripheral loop (with DAQ for the single channel of checking flow) from the main loop, and when the peripheral loop determines if flow has initalised, respond back to the main loop with the okay.
    I think much of my confusion is in the interaction of the loops and the default feedback nodes that labview is putting in willy nilly. Would the only solution be to have two 'main' loops that don't communicate with eachother but rather do the same thing while operating on different timing? Tell me if you want me to post the file (although its on an unnetworked computer and I didn't think it would be too useful).
    Thanks+ Curran
    Solved!
    Go to Solution.

    Here it is! It is not in any form of completion unfortunately.
    So reading in the temp with NI9213 and watercolumn height with NI9215, we determine to turn on the pump with NI9472. NI9421 determines whether the pump is on (there is flow) and I must respond accordingly.
    I have 3 scenarios similar to this one as well, so having redundant loops with different timing like I mentioned would be way to heavy. I think I may have though up of a solution? At the time the pump is initiated, we record the iteration and wait for a number of iterations that correspond to 10s to pass before fulfilling the pump shutoff requirement?
    Attachments:
    rewettin1.vi ‏15 KB

  • Problem with resultset.next inside 817 DB

    I have a java class running inside 817 database.
    I have a prepared statement that gets some records and loops through them and writes a record into another table.
    The SQL statement should produce 3000 records but only 566 get logged in the loop.
    I have looked at/tried everything. NOTHING seems wrong but jus tI dont get alll the records. The datatset is not truncated, records are missing ramdomly throught, ie recs 1-4 are OK then 5,6,7 are missing etc..
    Anyone know what the prb might be, its really weird and driving me nuts
    Rob
    null

    thank you for the pointers.
    For the RS is empty I've done a check with
    if(selectRs.next()!=null), even though
    next() is never suppose to be null, Yeah, you needn't bother with that. It's never supposed to be null, and if it is, there's a bug in the executeQuery method.
    ?so that confuses
    me. I've also put Sys.outs before & after the if
    statement & found it never prints out the System.out
    after the if(rs.next()). & I've stepped
    through with my WAS Debugger as a last restort to see
    what's going on. :$ So you're saying you put a print statement as the first statement right inside if (rs.next()) and it didn't get executed?
    I did do as you suggested with the
    count(*) & it did return a count of 1.You did that in your Java code? Changing only what you're selecting from those couple of columns to count(*), leaving the from and where alone?
    I am catching the SQLException for the try but
    nothing for the
    a_ruleSyntax.equals(current_ruleSyntax).Not sure what you're saying here, and not sure what your catch block looks like.
    I have put a System.out for if the equals returns
    false.
    Do you have any other ideas?Nope, sorry.
    If your answers to my questions above are "yes, that's what I'm doing," then I'm out of ideas, unless there's some exception that you're smothering.

  • Problems with ResultSet

    I'm working with Application Server WebLogic 5.1.
    In my Servlet or JSP why can't I invoke the ResultSet methods getRow, afterLast, beforeFirst
    when the method next works?
    My error message is:
    Servlet failed with Exception java.lang.AbstractMethodError

    those methods can only be used with a "scrollable" ResultSet. If your ResultSet was not created as a scrollable resultset, these methods can't be used. Another reason could be that your driver does not support the scrollable resultset. Post the statement/resultset code so that we can give you more accurate advice.
    Jamie

  • Problems with ResultSet.first()

    hi,
    i think, i can�t reset the pointer of a resultSet to the fist element. why?
    code:
    ResultSet rs ....
    while (rs.next()) // this is ok!!!
    //a bit later:
    rs.first()
    while ( rs.next() ) // does nothing...
    thanx for any help
    jules

    the cursor is not positioned in the same place before the two loops begin.
    ResultSet rs ....
    while (rs.next()) // this is ok!!!
    //a bit later:
    rs.first()
    while ( rs.next() ) // does nothing...
    { ... }if you have 4 rows of data then the first row you would get rows 1,2,3 and 4 in the second loop you would get 2,3 and 4 because first put you on row 1 and the first call to next puts you on row 2.
    you should do this instead...
    while(rs.next()){
    // do something
    rs.beforeFirst();
    while(rs.next()){
      // do something else
    }now those loops are the same.

  • Problems with indexing and Apple Loops on External Drive

    Ok, so I've recently moved my entire "Apple Loops" folder to an external drive and created an alias pointing back the "Audio" folder where the apple loops folder used to reside. The problem is when I bring up the loop browser, it's not finding the loops. Do I need to move the Apple Loops Index to the external hard drive as well? I assumed by creating an alias, it would just go to my external drive.

    Someone had said that it's better to use the alias for the apple loops since Logic will always go to where it expects the loops to be first. Which I'm assuming would be faster. But, if it truly doesn't matter and I should just drop all my apple loop folders one by one from my external hard drive, then I"ll do that. Anyone heard about what's faster....alias Vs. external HD direct path?

  • Problem with resultset FetchSize() method

    I am making call to stored procedure.I have set the fetchsize of result set to 1000.Even though the size is set for first fetch only 10 records are fectched which is default size and for next fetch 1000 records are returned.
    I am using Tomcat web server and oci driver.
    Can anyone pls help me i need all 1000 records in first fetch

    I am making call to stored procedure.I have set the
    fetchsize of result set to 1000.Even though the size
    is set for first fetch only 10 records are fectched
    which is default size and for next fetch 1000 records
    are returned.
    I am using Tomcat web server and oci driver.
    Can anyone pls help me i need all 1000 records in
    first fetchI believe that fetchSize is a suggestion to the jdbc driver, not a command. On some drivers it is ignored, on others it helps. It might help to know:
    How do you know that 10 and then 1000 rows are returned?
    What is the reason for your requirement of 1000 rows on the first call?

  • Problem with ResultSet

    Hi all,
    i m giving select query n after that rs = prepareStmt.executeQuery();
    after that i gave one sout to chk the flow it is coming after that statement properly.and after that i gave :---
    while (rs.next())
    sout("test");
    but it didn't print. if i run that query separately it is giving 6 records.
    Can u plz suggest what would be the reason behind it???
    Thanks n Regards,
    Sneha

    In a web application (JSP) use a data source instead of DriverManager.
    Re: Database connection in Simple JSP

  • Re: problem with char's and loops??

    You have to type out the full expression:
    If (variable != "a"
    && variable != "b"
    && variable != "c")

    ok, thanks, lemme try and get this to work

  • Qsm pc, problem with stop loop

    Hello,
    i tested queue producer/consument with event case, but i have problem with stop the both loop, can you help me with attachment ?
    Attachments:
    queue_mereni_1.zip ‏46 KB
    Global_queue.zip ‏3 KB

    thanks for your answer,
    i had problem with upload *.vi (some mistake), so when a upload *.zip it was ok, but i do not know why..
    please, when i put time out constatn, so when i push "stop" then both loops end - it is ok BUT:
    when i push "stop 2" button (for the second loop) so there is error (in attachment), please do you know why?
    i am sorry for a lot of questions but i try understand it..
    thank you
    Attachments:
    qsm.jpg ‏31 KB

Maybe you are looking for